Interface ObjectDeserializer
-
- All Known Subinterfaces:
AutowiredObjectDeserializer
- All Known Implementing Classes:
AbstractDateDeserializer,AtomicCodec,AwtCodec,BigDecimalCodec,BigIntegerCodec,BooleanCodec,ByteBufferCodec,CalendarCodec,CharacterCodec,CharArrayCodec,CollectionCodec,ContextObjectDeserializer,DateCodec,EnumCreatorDeserializer,EnumDeserializer,FloatCodec,GuavaCodec,IntegerCodec,JavaBeanDeserializer,JavaObjectDeserializer,Jdk8DateCodec,JodaCodec,JSONPDeserializer,LongCodec,MapDeserializer,MiscCodec,MonetaCodec,NumberDeserializer,ObjectArrayCodec,OptionalCodec,PropertyProcessableDeserializer,ReferenceCodec,SqlDateDeserializer,StackTraceElementDeserializer,StringCodec,ThrowableDeserializer,TimeDeserializer
public interface ObjectDeserializerInterface representing a custom deserializer for Json. You should write a custom deserializer, if you are not happy with the default deserialization done by Gson. You will also need to register this deserializer through
ParserConfig.putDeserializer(Type, ObjectDeserializer).public static enum OrderActionEnum { FAIL(1), SUCC(0); private int code; OrderActionEnum(int code){ this.code = code; } } public static class OrderActionEnumDeser implements ObjectDeserializer { public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { Integer intValue = parser.parseObject(int.class); if (intValue == 1) { return (T) OrderActionEnum.FAIL; } else if (intValue == 0) { return (T) OrderActionEnum.SUCC; } throw new IllegalStateException(); } public int getFastMatchToken() { return JSONToken.LITERAL_INT; } }You will also need to register
OrderActionEnumDeserto ParserConfig:ParserConfig.getGlobalInstance().putDeserializer(OrderActionEnum.class, new OrderActionEnumDeser());
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Tdeserialze(DefaultJSONParser parser, Type type, Object fieldName)fastjson invokes this call-back method during deserialization when it encounters a field of the specified type.intgetFastMatchToken()
-
-
-
Method Detail
-
deserialze
<T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName)
fastjson invokes this call-back method during deserialization when it encounters a field of the specified type.In the implementation of this call-back method, you should consider invoking
JSON.parseObject(String, Type, Feature[])method to create objects for any non-trivial field of the returned object.- Parameters:
parser- context DefaultJSONParser being deserializedtype- The type of the Object to deserialize tofieldName- parent object field name- Returns:
- a deserialized object of the specified type which is a subclass of
T
-
getFastMatchToken
int getFastMatchToken()
-
-