我使用JAXB
和JSONProvider
类在我的 REST 服务中生成对客户端的响应。我发现了一件有趣的事情。我有映射:
@XmlRootElement(name = "fooRoot")
@XmlAccessorType(XmlAccessType.FIELD)
public class WSBar {
private WSFooTO foos;
//...
}
@XmlRootElement(name = "foos")
@XmlAccessorType(XmlAccessType.FIELD)
public class WSFooTO {
private WSDateTO one;
private WSDateTO two;
private WSDateTO three;
private WSDateTO four;
//....
}
当我设置响应空对象时,我的意思是:就在new WSDateTO()
之后new WSFooTO ()
,我收到这样的答案:
{"fooRoot":{
"foos":{
"one":"",
"two":"",
"three":"",
"four":""
}
}}
为什么会这样?我希望它应该是:“one”:null,“two”:null