'error :com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gamaray