Spring 为什么大摇大摆';s api文档响应包装在附加JSON对象中?
我在Spring Boot应用程序中添加了swagger,包括依赖项:Spring 为什么大摇大摆';s api文档响应包装在附加JSON对象中?,spring,spring-boot,swagger,swagger-2.0,Spring,Spring Boot,Swagger,Swagger 2.0,我在Spring Boot应用程序中添加了swagger,包括依赖项: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.3.1</version> </dependency> 我现在可以访问/v2/api文档,并获得一些似乎描述我的api
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.3.1</version>
</dependency>
我现在可以访问/v2/api文档
,并获得一些似乎描述我的api的JSON。但是,JSON被包装在另一个JSON对象中,如下所示(缩写):
{“值”:“{\“招摇过市\”:\“2.0\”,\“信息\”:…}
{“value”:“…”}
对象是不需要的,它会在swagger ui中导致错误。PetStore示例没有此额外级别。这是错误还是配置问题
PS:我还为此创建了一个的模型,上面的人给我指出了正确的方向。问题如下:
我使用Gson而不是Jackson来反序列化Json。当类型为springfox.documentation.spring.web.Json.Json
的对象序列化时,Jackson考虑了包含的注释,但Gson忽略了它。对面的人给我指出了正确的方向。问题如下:
我使用Gson而不是Jackson来反序列化Json。当类型为springfox.documentation.spring.web.Json.Json
的对象序列化时,Jackson会考虑包含的注释,但Gson会忽略它
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(Predicates.or(PathSelectors.regex("...")))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(...);
}
}