Ignoring new fields in JSON objects when using Jackson
Hello! I'm a beginner Java developer and I've encountered a problem while working with JSON and the Jackson library.
I have a REST API that returns JSON with user data. My User class contains fields id, name, and email. Everything worked fine until the API added a new field phoneNumber to the JSON response. Now when I try to deserialize, I get an exception:
```
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "phoneNumber" (class User), not marked as ignorable
```
Here is my code:
```java
public class User {
private int id;
private String name;
private String email;
// getters and setters
}
// Deserialization
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(jsonString, User.class);
```
I've al
No answers yet.
Log in to leave an answer
Blogs