简体   繁体   English

在 Open API 3 中无法将类型“java.lang.String”的属性值转换为所需类型

[英]Failed to convert property value of type 'java.lang.String' to required type in Open API 3

I have a @RestController with such method我有一个带有这种方法的@RestController

@RestController
public MyController {

@Operation(summary = "Some text", description = "Some text again"
@GetMapping("/route")
public MyClassResponse getSomething(
@Parameter(name = "My request", description = "My request") MyRequest request
) {

    // to do smth

    return response
}

where MyRequest is MyRequest 在哪里

public class MyRequest {

private int param1;

private String param2;

private MyClass param3;

}

and MyClass looks like MyClass 看起来像

public class MyClass {

private int clazzParam1;
private int clazzParam2;
}

First of all, Swagger shows parameter MyRequest like body首先,Swagger 显示参数 MyRequest like body

{
"param1" : 0;
"param2" : "string",
"param3" : {
    "clazzParam1" : 0,
    "clazzParam2" : 0
    }
}

but I would like to see every parameter like this但我想看到这样的每个参数

Second when I try make request, I get this curl其次,当我尝试提出请求时,我得到了这个 curl

http://localhost:8080/route?param1=0&param2=string&param3=clazzParam1,0,clazzParam2,0 http://localhost:8080/route?param1=0&param2=string&param3=clazzParam1,0,clazzParam2,0

instead反而

http://localhost:8080/route?param1=0&param2=string&param3.clazzParam1=0&param3.clazzParam2=0 http://localhost:8080/route?param1=0&param2=string&param3.clazzParam1=0&param3.clazzParam2=0

Therefore response contain next failure Failed to convert property value of type 'java.lang.String' to required type 'MyClass' for property 'param3'.因此响应包含下一个失败无法将类型“java.lang.String”的属性值转换为属性“param3”所需的类型“MyClass”。

How should I use annotations to get what I want?我应该如何使用注释来获得我想要的东西? For various reasons I can't use.yaml description.由于各种原因我无法使用。yaml 描述。 Thank you.谢谢你。

@ParameterObject is answer. @ParameterObject 是答案。 It unpacking object to parameters in Swagger UI它将 object 解包到 Swagger UI 中的参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [无法将类型'java.lang.String []'的属性值转换为属性的必需类型'java.util.List' - [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.List' for property 无法将类型为java.lang.String的属性值转换为属性电话所需的long类型; 嵌套的超验 - Failed to convert property value of type java.lang.String to required type long for property phone; nested exce 无法将“java.lang.String”类型的属性值转换为属性“id”所需的类型“int” - Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'id' 无法将 [java.lang.String] 类型的属性值转换为所需类型 [java.time.LocalDate] - Failed to convert property value of type [java.lang.String] to required type [java.time.LocalDate] 无法将 java.lang.String 类型的属性值转换为所需类型 java.util.Date - Failed to convert property value of type java.lang.String to required type java.util.Date [无法将'java.lang.String'类型的属性值转换为所需的'java.sql.Time'类型 - [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Time' 无法将类型'java.lang.String'的属性值转换为必需类型'java.util.Date' - Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' 无法将 java.lang.String[] 类型的属性值转换为所需的类型 java.util.List - Failed to convert property value of type java.lang.String[] to required type java.util.List 无法将类型java.lang.String的属性值转换为所需的类型java.time.LocalDateTime - Failed to convert property value of type java.lang.String to required type java.time.LocalDateTime 无法将“java.lang.String”类型的属性值转换为所需类型“java.sql.Date” - Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM