springboot整合gson打开swagger报错:Unable to render this definition。The provided definition does not specify a valid version field.

 

Unable to render this definition

The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).

 

springboot整合gson之后打开swagger会报错,

 

 

将gson获取方式改下

 

import springfox.documentation.spring.web.json.Json;

 

复制代码
private static final Gson gson = new GsonBuilder()
            .registerTypeAdapter(Json.class, new SpringfoxJsonToGsonAdapter())
            .create();


    public static Gson getGson() {
        return gson;
    }

    private static class SpringfoxJsonToGsonAdapter implements JsonSerializer<Json> {
        @Override
        public JsonElement serialize(Json json, Type type, JsonSerializationContext context) {
            final JsonParser parser = new JsonParser();
            return parser.parse(json.value());
        }
    }
复制代码

 

相关依赖,已经引入了就不需要了

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0</version>
            <scope>compile</scope>
        </dependency>

 

posted @   yvioo  阅读(3029)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-06-29 centos使用docker安装clickhouse
2021-06-29 JAVA简单整合protoc文件
点击右上角即可分享
微信分享提示