I have a POJO that has the following structure:
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Item")
public class Item implements java.io.Serializable
{
private String attribute1;
private String attribute2;
@XmlElement
public String getAttribute1() {
return attribute1;
}
@XmlElement
public String getAttribute2() {
return attribute2;
}
public void setAttribute1(String attribute1) {
this.attribute1 = attribute1;
}
public void setAttribute2(String attribute2) {
this.attribute2 = attribute2;
}
}
Now on a webservice call, the XML returned to the client will have the structure:
<Item>
<attribute1>Some_Value</attribute1>
<attribute2>Some_Value</attribute2>
</Item>
However suppose any of the attributes are null, then the returned XML does not have that particular attribute tag.
For example, if attribute2 is null then the XML structure is:
<Item>
<attribute1>Some_Value</attribute1>
</Item>
My requirement is that the attribute tag should remain as an empty tag. The structure should be like:
<Item>
<attribute1>Some_Value</attribute1>
<attribute2></attribute2>
</Item>
Is this possible in RestEasy ? What are the changes that I will have to do to implement this? Please can someone help me on this.