I have the JSON looks like the following:
{
"name":"John",
"n_age":500
}
and I have a class Person:
public class Person {
private final String name;
private final int age;
@JsonCreator
public Person(@JsonProperty("name") String name) {
this.name = name;
this.age = 100;
}
public String getName() {
return name;
}
@JsonGetter("n_age")
public int getAge() {
return age;
}
}
I need to deserialize and serialize it, but when I'm trying to deserialize this JSON I get unexpected result.
public static void main(String... args) {
ObjectMapper mapper = new ObjectMapper();
Person person = mapper.readValue(args[0], Person.class);
System.out.println(person.getAge()); // I got 500, but I expect 100.
}
Why when I'm trying to deserialize it the @JsonGetter annotation is used for it?
How can I disable @JsonGetter annotation when I try to deserialize the JSON?