I am using Jackson to serialize some beans into JSON, inside an application that is using Spring Boot 1.5.
I noticed that to serialize a bean using the @JsonCreator
correctly, I have to declare the getter method for each property, plus the @JsonProperty
annotation.
public class Person {
private final String name;
private final int age;
@JsonCreator
public Person(@JsonProperty("name") String name,
@JsonProperty("age") int age) {
this.name = name;
this.age = age;
}
public String getName() {
return this.name;
}
public int getAge() {
return this.age;
}
}
If I remove methods getName
and getAge,
Jackson does not serialize the associated propertiy. Why does Jackson also need the getter methods?