java - Construct specific instance of ObjectWriter from the shared ObjectMapper in Jackson 2 to ignore null fields -
i working jackson 2 , cxf.
i have done lots of research find clean , safe way writer object shared object mapper given cxf un/marshaling json. cannot use annotation or set mapper object ignore null fields when serializing due business logic.
the code below seem correct, output json still include null fields. please !!
objectwriter writer = this.jacksonmapper.writer().without( serializationfeature.write_null_map_values ) ; if( writer.isenabled( serializationfeature.write_null_map_values ) ) { system.out.println("oppa gangname style"); } string json = null; try { json = writer.writevalueasstring( myobject ); system.out.println ( json ) ; } catch (jsonprocessingexception e) { throw new runtimeexception() ; }
the if case verify have successful disable serializationfeature.write_null_map_values. however, result still include null fields.
i'm using older jackson version works me:
jsonfactory factory = new jsonfactory(); objectmapper mapper = new objectmapper(factory); mapper.setserializationinclusion(inclusion.non_null); return mapper.writevalueasstring(input);
the docs serializationfeature.write_null_map_values
applies generating json strings map
objects.
Comments
Post a Comment