Search in sources :

Example 1 with ContextObjectDeserializer

use of com.alibaba.fastjson.parser.deserializer.ContextObjectDeserializer in project fastjson by alibaba.

the class DefaultFieldDeserializerBug569 method parseField.

@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        getFieldValueDeserilizer(parser.getConfig());
    }
    Type fieldType = fieldInfo.fieldType;
    if (objectType instanceof ParameterizedType) {
        ParseContext objContext = parser.getContext();
        objContext.type = objectType;
        fieldType = FieldInfo.getFieldType(this.clazz, objectType, fieldType);
    }
    // ContextObjectDeserializer
    Object value;
    if (fieldValueDeserilizer instanceof JavaBeanDeserializer) {
        JavaBeanDeserializer javaBeanDeser = (JavaBeanDeserializer) fieldValueDeserilizer;
        value = javaBeanDeser.deserialze(parser, fieldType, fieldInfo.name, fieldInfo.parserFeatures);
    } else {
        if (this.fieldInfo.format != null && fieldValueDeserilizer instanceof ContextObjectDeserializer) {
            value = //
            ((ContextObjectDeserializer) fieldValueDeserilizer).deserialze(parser, fieldType, fieldInfo.name, fieldInfo.format, fieldInfo.parserFeatures);
        } else {
            value = fieldValueDeserilizer.deserialze(parser, fieldType, fieldInfo.name);
        }
    }
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        DefaultJSONParser.ResolveTask task = parser.getLastResolveTask();
        task.fieldDeserializer = this;
        task.ownerContext = parser.getContext();
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.name, value);
        } else {
            setValue(object, value);
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParseContext(com.alibaba.fastjson.parser.ParseContext) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) ContextObjectDeserializer(com.alibaba.fastjson.parser.deserializer.ContextObjectDeserializer) JavaBeanDeserializer(com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer)

Aggregations

DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)1 ParseContext (com.alibaba.fastjson.parser.ParseContext)1 ContextObjectDeserializer (com.alibaba.fastjson.parser.deserializer.ContextObjectDeserializer)1 JavaBeanDeserializer (com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1