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