sumit sachdeva
sumit sachdeva

Reputation: 439

Local override for setSerializationInclusion(Include.NON_NULL) in ObjectMapper

In my spring application in WebMvcConfigurerAdapter, CustomObjectMapper is added in HttpMessageConverter. The CustomObjectMapper has setSerializationInclusion(Include.NON_NULL). For 1 particular pojo returned via Spring's ResponseBody I want null properties to be returned as well. I cannot change global setting as it will impact all controllers endpoints. Any suggestions ?

Upvotes: 0

Views: 352

Answers (1)

ilooner
ilooner

Reputation: 2560

You can create a mixin for the Pojo of interest and set the mixin on your CustomObjectMapper. This other answer shows exactly how to do this.

Upvotes: 1

Related Questions