I use MOXy to create XML responses for a SOAP web service and I need some tags to be printed even though the value is null. I'm using MOXy's XmlNullPolicy annotation for that purpose.
Here's an example:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"prop1",
"prop2"
})
@XmlRootElement(name = "Response")
public class Response {
@XmlElement(name = "Prop1")
@XmlSchemaType(name = "string")
@XmlNullPolicy(nullRepresentationForXml = XmlMarshalNullRepresentation.EMPTY_NODE)
protected MyEnumType prop1;
@XmlElement(name = "Prop2")
@XmlNullPolicy(nullRepresentationForXml = XmlMarshalNullRepresentation.EMPTY_NODE)
protected String prop2;
}
I'm expecing the following resulting XML:
<Response>
<Prop1/>
<Prop2/>
</Response>
But I'm getting:
<Response>
<Prop2/>
</Response>
Prop1 is missing even though XmlNullPolicy annotation is correctly defined.
Any idea or solution?