1

I am trying to get an XML output from a restEasy service. And its working fine. The problem is i am not able to see elements which dont have any values. I used @xmlElement in domain class wherever necessary. In Json response, i can see elements with null values.This is not working with XML. For Example:

JSON Response: "chemStructure": { "inchi": null, "inchiKey": null, "smiles": null, "iupac": null, "imageUri": null, "notation": null }

XML Response:

I want to see atleast the elemenst with empty tags

Vishwa
  • 117
  • 1
  • 2
  • 12

1 Answers1

0

By default JAXB (which is the default binding layer for JAX-RS implementations such as RESTEasy) will not marshal null values. You can change this behaviour by specifying the nillable setting on @XmlElement.

@XmlElement(nillable=true)
private String imageUri;

Then a null value will be represented in XML with the xsi:nil attribute.

<imageUri xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

For More Information

bdoughan
  • 147,609
  • 23
  • 300
  • 400