1

In a Glassfish/Jersey JAX-RS web application, how can I instruct the JSON provider (which defaults to MOXy in Jersey 2.22) to marshall null fields with JSON null value instead of skip them? I understand the use of @XmlElement(nillable = true), but since I need it for all classes fields it would be quite cumbersome to add it everywhere.

Giovanni Lovato
  • 2,183
  • 2
  • 29
  • 53

1 Answers1

0

You can use MOXy @XmlNullPolicy:

@XmlNullPolicy(emptyNodeRepresentsNull = true, nullRepresentationForXml = XmlMarshalNullRepresentation.EMPTY_NODE)

Taken from: https://stackoverflow.com/a/11748678/1986499 (Option #2)

Community
  • 1
  • 1
Imperative
  • 3,138
  • 2
  • 25
  • 40