0
问题1问题:
是两个约JsonProperty
class Point {
private int x;
private int y;
@JsonCreator
public Point(@JsonProperty("x") int x, @JsonProperty("y") int y) {
this.x = x;
this.y = y;
}
}
和
class Point {
@JsonProperty("x")
private int x;
@JsonProperty("y")
private int y;
@JsonCreator
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
等同?
问题2:
如果我有没有出现在构造函数的参数,如字段:
class Point {
private int x;
private int y;
private int z;
@JsonCreator
public Point(@JsonProperty("x") int x, @JsonProperty("y") int y) {
this.x = x;
this.y = y;
z = 0;
}
}
不杰克逊仍然知道那场(z)和它的价值?
1.不,可能它们不相同。第一个是要走的路。第二种情况需要默认的构造函数,因为Jackson似乎并不试图从参数名称中猜出字段名称。 – user3159253 2014-10-31 15:10:41
2.使用默认设置Jackson简单地忽略所有私人字段。 – user3159253 2014-10-31 15:11:23