zoukankan      html  css  js  c++  java
  • swagger2 Illegal DefaultValue null for parameter type integer

    问题,为了方便调试,引入了swagger2,但是在第一次访问的时候总是报

    Illegal DefaultValue null for parameter type integer 让人看着很不输入

    定位问题

    很明显说是NumberFormatException,查看AbstractSerializableParameter的getExample得知

        @JsonProperty("x-example")
        public Object getExample() {
            if (this.example == null) {
                return null;
            } else {
                try {
                    if ("integer".equals(this.type)) {
                        return Long.valueOf(this.example);
                    }
    

    在进行转化的时候报错,在this.example == null判断的不对。

    解决

    方式1-修改源码

    将源码下载下来,进行编辑,把判断部分修改为if (example == null || example.isEmpty())
    之后将其打包上传到maven私服即可。
    弊端,修改源码只能上传到私服,麻烦,也比较难

    方式2-修改代码

        @ApiModelProperty("开始时间,时间戳")
        private Long timeBegin;
    

    修改为

        @ApiModelProperty(value = "开始时间,时间戳",example = "0")
        private Long timeBegin;
    

    很明显,最容易,但是改动的也不少。

    方式3-修改依赖

    看网上说在swagger-models 1.5.21版本修复了该问题

    所以要升级版本

    exclusions排除依赖


    通过maven integration extension插件将swagger-models 1.5.20依赖排除
    再引入1.5.21依赖,如下代码

        <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger2</artifactId>
          <version>2.9.2</version>
          <exclusions>
            <exclusion>
              <artifactId>swagger-models</artifactId>
              <groupId>io.swagger</groupId>
            </exclusion>
          </exclusions>
        </dependency>
    

    再查看源码

    ok,完美解决!

  • 相关阅读:
    XML注释
    Mysql 查询不重复数据
    java 支持跨域
    蓝桥杯历届试题-打印十字图--Java
    以流的方式读取url中的参数
    写log日志,并读取log日志
    Java Memcached的使用
    PageInfo实现分页
    java swing 窗口在屏幕中默认显示的位置 居中位置显示
    简易计算器布局 BorderLayout JPanel GridLayout 混合
  • 原文地址:https://www.cnblogs.com/exmyth/p/15596980.html
Copyright © 2011-2022 走看看