0

For example, my Spring boot Java API was returning:

{
    "contact": "John Smith",
    "badgeNumber": "12345",
    "inProcess": true
}

Then I added SpringFox dependencies for Swagger and now all my API is returning:

{
    "contact": "John Smith",
    "badgeNumber": "12345",
    "supervisor": null,
    "inProcess": true,
    "employeeReference": null,
    "vacationDates": null
}

Everything in swagger is working smoothly, but I don't want these null fields to return. They should be excluded from the response by default. Any ideas?

doct03
  • 316
  • 3
  • 9
  • I think below answer will be useful. [stackoverflow answer](https://stackoverflow.com/questions/38147059/prevent-null-values-in-json-result-spring) – Asanka Sep 27 '18 at 16:41
  • @Asanka I have tried this and it does not work. – doct03 Sep 27 '18 at 18:31
  • @Asanka I have figured it out. That answer was partially correct for my use case. I had to include the @JsonInclude(JsonInclude.Include.NON_NULL) annotation at the class level, not at the ObjectMapper. – doct03 Sep 27 '18 at 18:51

0 Answers0