【问题标题】:How to get rid of "value" from swagger json {"value" :"{\"swagger\":\"2.0\", \"info\"{\" description? [duplicate]如何摆脱 swagger json {"value" :"{\"swagger\":\"2.0\", \"info\"{\" 描述中的“value”? [复制]
【发布时间】:2016-08-31 22:06:37
【问题描述】:

我在我的 spring 项目中使用 GsonHttpMessageConverter。当我使用 swagger 时,它会生成带有“值”的 json,例如 {"value" :"{\"swagger\":\"2.0\", \"info\"{\" description ...

由于上述格式,这实际上会破坏 swagger UI。它不应该生成“值”标签,但它正在生成。有没有合适的方法来解决这个问题?

【问题讨论】:

    标签: json spring swagger


    【解决方案1】:

    尝试按如下方式对您的类进行序列化:

    package springfpackage springfox.documentation.spring.web.json;
    import com.fasterxml.jackson.annotation.JsonRawValue;
    import com.fasterxml.jackson.annotation.JsonValue;
    
    public class Json {
      private final String value;
    
      public Json(String value) {
        this.value = value;
      }
    
      @JsonValue
      @JsonRawValue
      public String value() {
        return value;
      }
    }
    

    然后检查它应该可以正常工作!

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      相关资源
      最近更新 更多