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.
Asked
Active
Viewed 477 times
1

Giovanni Lovato
- 2,183
- 2
- 29
- 53
1 Answers
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
-
Do I need to add @XmlNullPolicy to all fields/classes? I'm looking for a configuration option to set this behaviour globally. – Giovanni Lovato Oct 19 '15 at 06:59
-
I don't know any option like that. – Imperative Oct 19 '15 at 11:24