Techiee Techiee - 1 month ago 15
JSON Question

How to get rid of "value" from swagger json {"value" :"{\"swagger\":\"2.0\", \"info\"{\" description?

I am Using GsonHttpMessageConverter in my spring project. When I use swagger, it is generating json with "Value" like {"value" :"{\"swagger\":\"2.0\", \"info\"{\" description ...

Which will actually break in swagger UI because of the above format. It shouldn't generate "value" tag, but it is generating. Is there any proper way to address this issue?

SRJ SRJ
Answer

Try serilaizing your class as follows:

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;
  }
}

And then check it should work fine!

Comments