Eliminating empty elements when marshalling with JAXB
Using JAXB (2) is it possible to ensure that null values are not marshalled as () empty elements. For instance
@XmlRootElement(name = "root")
public class Root {
@XmlElement(name = "name")
protected String name;
}
Currently if name is null then 开发者_运维知识库I am marshalling
<root>
<name/>
</root>
I would like to produce
<root>
</root>
instead.
i think u have missed something.. as u marshal it ,the string u are passing must not be null as with string null is also an string.. so in my opinion u must pass empty string rather than null.
精彩评论