当前位置:网站首页>swagger2 Illegal DefaultValue null for parameter type integer

swagger2 Illegal DefaultValue null for parameter type integer

2021-09-15 04:32:21 Dylansea

swagger2 Illegal DefaultValue null for parameter type integer_springmaven Of extensions The correct way to use
problem , For the convenience of debugging , Introduced swagger2, But on the first visit, always report

Illegal DefaultValue null for parameter type integer It makes people look very uncomfortable
swagger2 Illegal DefaultValue null for parameter type integer_spring_02

Location problem

Obviously NumberFormatException, see AbstractSerializableParameter Of getExample hear

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

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

An error is reported during conversion , stay this.example == null Wrong judgment .
swagger2 Illegal DefaultValue null for parameter type integer_ Source download _03

solve

The way 1- Modify source code

Download the source code , Editing , Revise the judgment section to if (example == null || example.isEmpty())
Then package and upload it to maven Private service .
disadvantages , The modified source code can only be uploaded to the private server , trouble , It's also harder

The way 2- Modify the code

take

    @ApiModelProperty(" Starting time , Time stamp ")
    private Long timeBegin;

      
  • 1.
  • 2.

It is amended as follows

    @ApiModelProperty(value = " Starting time , Time stamp ",example = "0")
    private Long timeBegin;

      
  • 1.
  • 2.

Obviously , The easiest , But there are many changes .

The way 3- Modify dependency

Look at what the Internet says swagger-models 1.5.21 Version fixes this problem
swagger2 Illegal DefaultValue null for parameter type integer_maven_04

So upgrade the version

exclusions Exclude dependence

swagger2 Illegal DefaultValue null for parameter type integer_ Time stamp _05
adopt maven integration extension The plug-in will swagger-models 1.5.20 Dependency exclusion
To introduce 1.5.21 rely on , The following code

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

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

Check the source code again
swagger2 Illegal DefaultValue null for parameter type integer_maven_06

ok, Perfect solution !

Facing the ocean ``` Spring flowers
 
 
 
 

版权声明
本文为[Dylansea]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/09/20210909112709642t.html

随机推荐