java - custom field serialization using jacson -
i want serialize few fields of class in custom way using jackson. wrote custom serializer this.but problem not able name of field in custom serializer. pojo class is
public static class foo { public string foo = "a"; @jsonserialize(using = customserializer.class) public string bar = "b"; @jsonserialize(using = customserializer.class) public string foobar = "c"; } and custom serializer class is
public class customserializer extends jsonserializer<string> { @override public void serialize(string t, jsongenerator jg, serializerprovider sp) throws ioexception, jsonprocessingexception { if(field.name.equals("a")) //do else if(filed.name.equals("b")) //do } } here want name of field being serialized. how can name of fields "a" , "b" in custom serializer ? thanks
i think, not possible now. can create 2 separate serializers each property. know, little workaround, should work.
Comments
Post a Comment