简体   繁体   English

错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段

[英]error :com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field

I'm trying to read the below json and map to the model object.我正在尝试阅读以下 json 和 map 到 model object。

Model class: Model class:

 public class User {
    private String name;
    private int age;
    private List<String> messages;
}

Below is the sample code used to map the json to model (MyModelData.java)下面是用于map json model的示例代码(MyModelData.java)

ObjectMapper mapper = new ObjectMapper();
    try {
        String jsonInString = "{\"age\":33,\"messages\":[\"msg 1\",\"msg 2\"],\"name\":\"mkyong\"}";
        User user1 = mapper.readValue(jsonInString, User.class);
        System.out.println(user1);
    } catch (Exception e) {
        System.out.println("ex " + e);
    }

Below is the exception:以下是例外情况:

   com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "age" (class com.dsr.User), not marked as ignorable (0 known properties: ])
 at [Source: (String)"{"age":33,"messages":["msg 1","msg 2"],"name":"mkyong"}"; line: 1, column: 10] (through reference chain: com.dsr.User["age"])

When mapping the json string to the model object it is showing the above exception.将 json 字符串映射到 model object 时显示上述异常。 The User class has age property defined.用户 class 定义了年龄属性。

I don't know if this is the only issue with your code but for ID:4 in the JSON after Claim related to issueID you are missing a closing speech mark.我不知道这是否是您的代码的唯一问题,但对于ID:4 in the JSON after Claim related to issueID您缺少结束语标记。

暂无
暂无

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

相关问题 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段 - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 解决com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段 - resolving com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“ g” - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “g” Jackson 反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别 - Jackson deserialization error: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 无法使用杰克逊,com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException将xml绑定到pojo:无法识别的字段 - can not bind xml to pojo using jackson, com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException 对象映射器给出异常:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段 - Object Mapper giving Exception: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field 引起:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“Status” - Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “Status” com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“消息”异常 - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “message” exception Java - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:无法识别的字段“”不可标记 - Java - com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" not marked as ignorable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM