Jersey serializing null values to json : How to skip

2.7k Views Asked by At

I am using Jersey 2.4 with spring.

When I am returning a response from a method with an annotation @Produces(MediaType.APPLICATION_JSON) on it, it also serialize the null values to json.

I don't want to serialize the fields that contains the null values.

Is there any solution for the same?

1

There are 1 best solutions below

4
On BEST ANSWER

Assuming, you are using Jackson for serialization, you can use the @JsonInclude(Include.NON_NULL) to your class to exclude the null values.