java - Jackson serialize field with different custom serializers -


is possible write n custom serializers particular field , use serializer , time use serializer b? have written custom serializers before have used them annotation not possible in case. avoid views since had write getter each serializer implementation then.

this have:

@jsonserialize(using = mongoidserializer.class) string id; 

this want:

@jsonserialize(using = <serializerdeclaredbypropertyfile>) string id; 

you write custom serializer use on property.

@jsonserialize(using = delegatingserializer.class) string id; 

the implementation that:

public class delegatingserializer extends jsonserializer<string>{     public void serialize(string value, jsongenerator jgen, serializerprovider provider) throws ioexception, jsonprocessingexception {        jsonserializer<string> serializer = getserializer();        serializer.serialize(value, jgen, provider);          }     private jsonserializer<string> getserializer() {        ...        return someserializerinstance;    }  } 

in getserializermethod return instance of correct serializer.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -