【发布时间】:2011-04-25 16:40:31
【问题描述】:
我想在 JSON 表示中将 null 对象编组为 null。 但是,现在,如果对象为空,我看不到 JSON 中的元素。
Example:
@XmlAccessType(FIELD)
@XmlType(name="foo" propOrder={"foo"}
class foo{
@XmlElement
private Integer foo;
private Integer another_foo;
..
getter()
setter()
}
在我的代码中,我将 foo 元素设置为 null。
但 JSON 表示不显示响应中的元素。
响应如下所示
"foo" :{
"another_foo":something
}
我尝试将 xml 元素属性设置为 nillable true。 (@XmlElement(nillable=true)
这使响应看起来像,
"foo" :{
"another_foo" : something
"foo":{nil :true}
}
我希望它像,
"foo" :{
"another_foo":something
"foo" : null
}
这里做错了什么?
【问题讨论】:
标签: java json api jaxb marshalling