[英]JSONProvider returns empty objects such as String
I use JAXB
and JSONProvider
class for generating response to client in my REST services. 我使用
JAXB
和JSONProvider
类在REST服务中生成对客户端的响应。 And I have found one interesting thing. 我发现了一件有趣的事情。 I have the mapping:
我有映射:
@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;
//....
}
When I set to the response empty objects, I mean: just new WSDateTO()
and new WSFooTO ()
After the, I recive answer like this: 当我将响应设置为空对象时,我的意思是:只是
new WSDateTO()
和new WSFooTO ()
之后,我会这样回答:
{"fooRoot":{
"foos":{
"one":"",
"two":"",
"three":"",
"four":""
}
}}
Why does it happen? 为什么会发生? I expect, that it should be: "one":null, "two":null
我希望它应该是:“ one”:null,“ two”:null
According to a JAXB tutorial the absence of a value can be expressed in three different ways: 根据JAXB 教程 ,值的缺失可以用三种不同的方式表示:
@XmlElement(required = true)
annotation @XmlElement(required = true)
注释的空字符串 xsi:nil
attribute using @XmlElement(nillable = true)
annotation @XmlElement(nillable = true)
注释的单独xsi:nil
属性 Answering strictly your question: JAXB does not support translating empty objects to null
. 严格回答您的问题:JAXB不支持将空对象转换为
null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.