What's difference between <foo></foo> and null in JAXB?
I am have created a Java Webservice application which uses JAXB. When I test my application using SoapUI and I send a SOAP message like <foo></foo>, it will convert to 0, but if there's no <foo> tag in my SOAP message, it will convert to null. Why is <foo></foo> not converted to null? How can I change it?
@WebMethod
public void test(Integer fo开发者_运维知识库o) {
System.out.print(foo);
}
null generally indicates "unknown". Since foo isn't present, there is absolutely NO information about it. You can't assign a default 0, because that might be absolutely wrong/catastropic. All you can do is say "I don't know", which boils down to null. On the other hand, <foo></foo> means that foo is present and is empty, which does generally boil down to a 0.
If you are using JAXB 2.2 then you can specify the @XmlElement(nillable=true) annotation at the parameter level to have the XML represented as xsi:nil="true".
@WebMethod
public void test(@XmlElement(nillable=true) Integer foo) {
System.out.print(foo);
}
加载中,请稍侯......
精彩评论