简体   繁体   English

面对 JSON 解析问题,无法从数组值 jackson.databind.exc.MismatchedInputException 反序列化类型为“java.lang.String”的值

[英]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.

相关问题 jackson.databind.exc.MismatchedInputException:无法反序列化java.lang.String的实例 - jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从 START_OBJECT 令牌中反序列化 `java.lang.String` 的实例 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token 状态”:400 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化java.lang.Boolean的实例 - status":400 com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.Boolean 无法从 mockmvc 的数组值中反序列化 `java.lang.String` 类型的值 - Cannot deserialize value of type `java.lang.String` from Array value from mockmvc com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化实例? - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance? com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 Object 的实例超出 START_ARRAY 令牌 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token 使用 jackson 读取嵌套的 json - MismatchedInputException:无法反序列化值 - reading nested json with jackson - MismatchedInputException: Cannot deserialize value java.lang.String 类型的值数组无法转换为 JSONObject - Value Array of type java.lang.String cannot be converted to JSONObject com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 START_OBJECT 令牌中的“java.util.ArrayList”实例 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token org.json.JSONException:类型为java.lang.String的值数组无法转换为JSONObject - org.json.JSONException: Value Array of type java.lang.String cannot be converted to JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM