I am trying to create a spring-boot application (v1.2.3) and expose my Rest API with SpringFox (swagger2) v2.0.0
my Swagger Spring config
@EnableSwagger2 @Configuration public class SwaggerConfig { @Bean public Docket myApi() { return new Docket(DocumentationType.SWAGGER_2) .genericModelSubstitutes(DeferredResult.class) .useDefaultResponseMessages(false) .forCodeGeneration(false) .pathMapping("/my-prj"); } }
I need to use gson to convert my pojo to json, and I do it like this:
@Configuration public class GsonHttpMessageConverterConfig { @Bean public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) { GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); converter.setGson(gson); return converter; } }
The problem is that when using GsonHttpMessageConverter , swagger v2 generates the wrong json:
{ "value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{\"name\":\"Contact Email\"},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http: ...
JSON has a value prefix, and real JSON becomes an escaped string.
this is how it should be if you don't use GsonHttpMessageConverter :
{ "swagger": "2.0", "info": { "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a ...
Is there a solution to create the right JAON Swagger without value and output?