[英]jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String
[英]Facing JSON parse issue, Cannot deserialize value of type `java.lang.String` from Array value jackson.databind.exc.MismatchedInputException
嘗試在我的郵遞員請求中包含數組時遇到 JSON 解析問題:
{
"id" : "0",
"number":["2222", "3333"]
}
寶約:
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;
}
控制器:
@PostMapping("/user")
public ResponseEntity<Object> getUser(@RequestBody(required=true)User user) {
痕跡:
"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.