I'm trying to read the below json and map to the model object.
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)
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. The User class has age property defined.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.