java - How do you override the null serializer in Jackson 2.0? -


i'm using jackson json serialization, , override null serializer -- specifically, null values serialized empty strings in json rather string "null".

all of documentation , examples i've found on how set null serializers refers jackson 1.x -- example, code @ bottom of http://wiki.fasterxml.com/jacksonhowtocustomserializers no longer compiles jackson 2.0 because stdserializerprovider no longer exists in library. web page describes jackson 2.0's module interface, module interface has no obvious way override null serializer.

can provide pointer on how override null serializer in jackson 2.0?

override jsonserializer serialize method below.

public class nullserializer extends jsonserializer<object> { public void serialize(object value, jsongenerator jgen, serializerprovider provider)    throws ioexception, jsonprocessingexception {    // json value want...     jgen.writestring(""); } } 

and create custom object mapper , set nullsearilizer default serializer show below.

public class customjacksonobjectmapper extends objectmapper {  public customjacksonobjectmapper() {     super();      defaultserializerprovider.impl sp = new defaultserializerprovider.impl();     sp.setnullvalueserializer(new nullserializer());     this.setserializerprovider(sp); } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -