1

I use JBoss EAP 7.1 with JAVA EE. I can exclude null fields in response using @JsonInclude(JsonInclude.Include.NON_NULL) annotation under class all filed. Does exist way to exclude globally (in all project) null values in all objects that resteasy return in response, for example here :

Response.status(Response.Status.OK).entity(objet).build()

1 Answers1

3

You need to configure ObjectMapper instance in your app:

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);

See also:

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
  • Is it possible to do that in Java EE application? I don't have spring there. And without adding new jars. ResteasyJacksonProvider is not found. – Олег Гаврилів Feb 28 '19 at 14:28
  • 1
    `Spring` is not required there. Second link shows how to do it. Also take a look on [Custom ObjectMapper with Jersey 2.2 and Jackson 2.1](https://stackoverflow.com/questions/18872931/custom-objectmapper-with-jersey-2-2-and-jackson-2-1), [Jersey Jackson and codehaus vs. fasterxml](https://stackoverflow.com/questions/16876482/jersey-jackson-and-codehaus-vs-fasterxml), [Jersey 2.6 Jackson provider registering](https://stackoverflow.com/questions/27935273/jersey-2-6-jackson-provider-registering) – Michał Ziober Feb 28 '19 at 14:40