Reputation: 15318
on setting an element:
element.setValue(null)
it marshalls the XML to
<element>
<value>null<value>
</element>
I am expecting it to be:
<element>
<value/>
</element>
or
<element />
Upvotes: 0
Views: 494
Reputation: 149057
JAXB does not marshal a null value as:
<foo>null</foo>
By default it will not marshal the element. If you annotate it with @XmlElement(nillable=true)
the xsi:nil
attribute will be used.
For More Information
Upvotes: 1
Reputation: 95
You have two options:
In the getter method of value you do so:
public String getValue(){
if(value == null)
return null;
return value;
}
In this case if you don't give a value to this field then you will have an empty element. Personnally, I prefer the first solution
Upvotes: 0
Reputation: 13746
Try to set to element.setValue("") , instead of null directly for the desired output.
Upvotes: 0
Reputation: 4014
You need to put @XmlValue annotation on getter method value
@XmlValue
public String getValue(){
}
further see How to represent null value as empty element with JAXB?
Upvotes: 0