Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring null values when marshaling an object to JSON with RESTeasy and Jettison

When RESTeasy marshals a POJO into XML, it will skip null values by default: See Jaxb marshaller always writes xsi:nil (even when @XmlElement(required=false, nillable=true)).

However, when marshaling to JSON, null properties are included. Is there any way to force the JSON output to match the XML output?

like image 840
Phyxx Avatar asked Nov 14 '22 15:11

Phyxx


1 Answers

To ensure that null values are not included in the JSON, the following annotation can be applied on the getter or public variable declaration: @JsonSerialize(include = Inclusion.NON_NULL)

like image 149
JordanB Avatar answered Dec 11 '22 05:12

JordanB