Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 为什么大摇大摆';s api文档响应包装在附加JSON对象中?_Spring_Spring Boot_Swagger_Swagger 2.0 - Fatal编程技术网

Spring 为什么大摇大摆';s api文档响应包装在附加JSON对象中?

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

我在Spring Boot应用程序中添加了swagger,包括依赖项:

<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(...);
    }
}