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