[英]Facing JSON parse issue, Cannot deserialize value of type `java.lang.String` from Array value jackson.databind.exc.MismatchedInputException
Facing a JSON parse issue when trying to include array in my postman request:尝试在我的邮递员请求中包含数组时遇到 JSON 解析问题:
{
"id" : "0",
"number":["2222", "3333"]
}
pojo:宝约:
public class User {
@Getter @Setter private String id;
@Getter @Setter private String[] number;
//i've also tried these:
@Getter @Setter private List<String> number;
@Getter @Setter private ArrayList<String> number;
}
Controller:控制器:
@PostMapping("/user")
public ResponseEntity<Object> getUser(@RequestBody(required=true)User user) {
Trace:痕迹:
"trace": "org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize value of type `java.lang.String` from Array value (token `JsonToken.START_ARRAY`);
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException:
Cannot deserialize value of type `java.lang.String` from Array value (token `JsonToken.START_ARRAY`)
at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 3, column: 13]
不要使用@Getter
和@Setter
注释,而是将@Data
放在你的类上,它将为你的类创建所需的构造函数!
向您的类添加无参数构造函数并使其可Serializable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.