java - How to ignore "null" or empty properties in json, globally, using Spring configuration -


i'm trying return properties have values, null ones being returned.

i know there's annotation ( @jsoninclude(include.non_null) ), need these in every single entity class.

so, question is: there way configure globally through spring config? (avoiding xml, preferably)

edit: seems question has been considered duplicate, don't think so. real question here how configure through spring config, couldn't find in other questions.

if using spring boot, easy as:

spring.jackson.serialization-inclusion=non_null 

if not, can configure objectmapper in mappingjackson2httpmessageconverter so:

@configuration class webmvcconfiguration extends webmvcconfigurationsupport {     @override     protected void extendmessageconverters(list<httpmessageconverter<?>> converters) {         for(httpmessageconverter converter: converters) {             if(converter instanceof mappingjackson2httpmessageconverter) {                 objectmapper mapper = ((mappingjackson2httpmessageconverter)converter).getobjectmapper()                 mapper.setserializationinclusion(include.non_null);             }         }     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -