简体   繁体   中英

How to marshall null fields in Jersey JAX-RS implementation?

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.

You can use MOXy @XmlNullPolicy :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM