在Jackson中,当您使用@JsonCreator
注释构造函数时,必须使用@JsonProperty
注释其参数。因此,这个构造函数
public Point(double x, double y) {
this.x = x;
this.y = y;
}
变成这样:
@JsonCreator
public Point(@JsonProperty("x") double x, @JsonProperty("y") double y) {
this.x = x;
this.y = y;
}
我不明白为什么这是必须的。你可以解释一下吗?