【发布时间】:2013-06-15 08:43:19
【问题描述】:
我有以下课程:
class Bean {
private int x;
private int y;
public Bean(int x, int y) {
this.x = x;
this.y = y;
}
@JsonProperty("x")
@JsonView(View1.class)
public void setX(int x) {
this.x = x;
}
public int getX() {
return this.x;
}
@JsonProperty("y")
public void setY(int y) {
this.y = y;
}
public int getY() {
return this.y;
}
}
还有一个观点:
class View1 {
}
我希望_mapper.writerWithView(View1.class).writeValueAsString(bean) 返回{"x":1},因为x 是唯一附加了视图的值,但我得到了{"x":1,"y":2}。
它为什么这样做,我怎样才能让它不这样做?我知道我可以删除 @JsonProperty("y"),但如果我选择使用普通 writer 而不是 writerWithView,我仍然希望能够序列化所有值。
【问题讨论】:
-
你确定 y 没有被设置在别处吗?
标签: java serialization jackson fasterxml json-view