Java 类com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask 实例源码

项目:boohee_v5.6    文件:DefaultFieldDeserializer.java   
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (this.fieldValueDeserilizer == null) {
        this.fieldValueDeserilizer = parser.getConfig().getDeserializer(this.fieldInfo);
    }
    if (objectType instanceof ParameterizedType) {
        parser.getContext().setType(objectType);
    }
    Object value = this.fieldValueDeserilizer.deserialze(parser, getFieldType(), this.fieldInfo.getName());
    if (parser.getResolveStatus() == 1) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(0);
    } else if (object == null) {
        fieldValues.put(this.fieldInfo.getName(), value);
    } else {
        setValue(object, value);
    }
}
项目:uavstack    文件:DefaultFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
    }

    if (objectType instanceof ParameterizedType) {
        ParseContext objContext = parser.getContext();
        objContext.setType(objectType);
    }

    Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.getName(), value);
        } else {
            setValue(object, value);
        }
    }
}
项目:itmarry    文件:DefaultFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
    }

    if (objectType instanceof ParameterizedType) {
        ParseContext objContext = parser.getContext();
        objContext.setType(objectType);
    }

    Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.getName(), value);
        } else {
            setValue(object, value);
        }
    }
}
项目:android_http_demo    文件:DefaultFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
    }

    Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.getName(), value);
        } else {
            setValue(object, value);
        }
    }
}
项目:AndroidNio    文件:DefaultFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
    }

    Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.getName(), value);
        } else {
            setValue(object, value);
        }
    }
}
项目:itmarry    文件:JSON.java   
public static void handleResovleTask(DefaultJSONParser parser, Object value) {
    List<ResolveTask> resolveTaskList = parser.getResolveTaskListDirect();
    if (resolveTaskList == null) {
        return;
    }
    int size = resolveTaskList.size();
    for (int i = 0; i < size; ++i) {
        ResolveTask task = resolveTaskList.get(i);
        FieldDeserializer fieldDeser = task.getFieldDeserializer();

        if (fieldDeser == null) {
            continue;
        }

        Object object = null;
        if (task.getOwnerContext() != null) {
            object = task.getOwnerContext().getObject();
        }

        String ref = task.getReferenceValue();
        Object refValue;
        if (ref.startsWith("$")) {
            refValue = parser.getObject(ref);
        } else {
            refValue = task.getContext().getObject();
        }
        fieldDeser.setValue(object, refValue);
    }
}
项目:android_http_demo    文件:JSON.java   
public static <T> int handleResovleTask(DefaultJSONParser parser, T value) {
    if (parser.isEnabled(Feature.DisableCircularReferenceDetect)) {
        return 0;
    }

    int size = parser.getResolveTaskList().size();
    for (int i = 0; i < size; ++i) {
        ResolveTask task = parser.getResolveTaskList().get(i);
        FieldDeserializer fieldDeser = task.getFieldDeserializer();

        Object object = null;
        if (task.getOwnerContext() != null) {
            object = task.getOwnerContext().getObject();
        }

        String ref = task.getReferenceValue();
        Object refValue;
        if (ref.startsWith("$")) {
            refValue = parser.getObject(ref);
        } else {
            refValue = task.getContext().getObject();
        }
        fieldDeser.setValue(object, refValue);
    }

    return size;
}
项目:AndroidNio    文件:JSON.java   
public static <T> int handleResovleTask(DefaultJSONParser parser, T value) {
    if (parser.isEnabled(Feature.DisableCircularReferenceDetect)) {
        return 0;
    }

    int size = parser.getResolveTaskList().size();
    for (int i = 0; i < size; ++i) {
        ResolveTask task = parser.getResolveTaskList().get(i);
        FieldDeserializer fieldDeser = task.getFieldDeserializer();

        Object object = null;
        if (task.getOwnerContext() != null) {
            object = task.getOwnerContext().getObject();
        }

        String ref = task.getReferenceValue();
        Object refValue;
        if (ref.startsWith("$")) {
            refValue = parser.getObject(ref);
        } else {
            refValue = task.getContext().getObject();
        }
        fieldDeser.setValue(object, refValue);
    }

    return size;
}
项目:GitHub    文件:ASMDeserializerFactory.java   
private void _deserialze_obj(Context context, MethodVisitor mw, Label reset_, FieldInfo fieldInfo,
                             Class<?> fieldClass, int i) {
    Label matched_ = new Label();
    Label _end_if = new Label();

    mw.visitVarInsn(ALOAD, context.var("lexer"));
    mw.visitVarInsn(ALOAD, 0);
    mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_prefix__", "[C");
    mw.visitMethodInsn(INVOKEVIRTUAL, JSONLexerBase, "matchField", "([C)Z");
    mw.visitJumpInsn(IFNE, matched_);
    mw.visitInsn(ACONST_NULL);
    mw.visitVarInsn(ASTORE, context.var(fieldInfo.name + "_asm"));

    mw.visitJumpInsn(GOTO, _end_if);

    mw.visitLabel(matched_);

    _setFlag(mw, context, i);

    // increment matchedCount
    mw.visitVarInsn(ILOAD, context.var("matchedCount"));
    mw.visitInsn(ICONST_1);
    mw.visitInsn(IADD);
    mw.visitVarInsn(ISTORE, context.var("matchedCount"));

    _deserObject(context, mw, fieldInfo, fieldClass, i);

    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getResolveStatus", "()I");
    mw.visitLdcInsn(com.alibaba.fastjson.parser.DefaultJSONParser.NeedToResolve);
    mw.visitJumpInsn(IF_ICMPNE, _end_if);

    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getLastResolveTask", "()" + desc(ResolveTask.class));
    mw.visitVarInsn(ASTORE, context.var("resolveTask"));

    mw.visitVarInsn(ALOAD, context.var("resolveTask"));
    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getContext", "()" + desc(ParseContext.class));
    mw.visitFieldInsn(PUTFIELD, type(ResolveTask.class), "ownerContext", desc(ParseContext.class));

    mw.visitVarInsn(ALOAD, context.var("resolveTask"));
    mw.visitVarInsn(ALOAD, 0);
    mw.visitLdcInsn(fieldInfo.name);
    mw.visitMethodInsn(INVOKEVIRTUAL, type(JavaBeanDeserializer.class), "getFieldDeserializer",
                       "(Ljava/lang/String;)" + desc(FieldDeserializer.class));
    mw.visitFieldInsn(PUTFIELD, type(ResolveTask.class), "fieldDeserializer", desc(FieldDeserializer.class));

    mw.visitVarInsn(ALOAD, 1);
    mw.visitLdcInsn(com.alibaba.fastjson.parser.DefaultJSONParser.NONE);
    mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "setResolveStatus", "(I)V");

    mw.visitLabel(_end_if);

}
项目:boohee_v5.6    文件:MapDeserializer.java   
public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map, Type keyType, Type valueType, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 12 || lexer.token() == 16) {
        ObjectDeserializer keyDeserializer = parser.getConfig().getDeserializer(keyType);
        ObjectDeserializer valueDeserializer = parser.getConfig().getDeserializer(valueType);
        lexer.nextToken(keyDeserializer.getFastMatchToken());
        ParseContext context = parser.getContext();
        while (lexer.token() != 13) {
            try {
                if (lexer.token() == 4 && lexer.isRef()) {
                    Map<Object, Object> object = null;
                    lexer.nextTokenWithColon(4);
                    if (lexer.token() == 4) {
                        String ref = lexer.stringVal();
                        if ("..".equals(ref)) {
                            object = context.getParentContext().getObject();
                        } else if ("$".equals(ref)) {
                            ParseContext rootContext = context;
                            while (rootContext.getParentContext() != null) {
                                rootContext = rootContext.getParentContext();
                            }
                            object = rootContext.getObject();
                        } else {
                            parser.addResolveTask(new ResolveTask(context, ref));
                            parser.setResolveStatus(1);
                        }
                        lexer.nextToken(13);
                        if (lexer.token() != 13) {
                            throw new JSONException("illegal ref");
                        }
                        lexer.nextToken(16);
                        parser.setContext(context);
                        return object;
                    }
                    throw new JSONException("illegal ref, " + JSONToken.name(lexer.token()));
                }
                if (map.size() == 0 && lexer.token() == 4 && JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal())) {
                    lexer.nextTokenWithColon(4);
                    lexer.nextToken(16);
                    if (lexer.token() == 13) {
                        lexer.nextToken();
                        return map;
                    }
                    lexer.nextToken(keyDeserializer.getFastMatchToken());
                }
                Object key = keyDeserializer.deserialze(parser, keyType, null);
                if (lexer.token() != 17) {
                    throw new JSONException("syntax error, expect :, actual " + lexer.token());
                }
                lexer.nextToken(valueDeserializer.getFastMatchToken());
                map.put(key, valueDeserializer.deserialze(parser, valueType, key));
                if (lexer.token() == 16) {
                    lexer.nextToken(keyDeserializer.getFastMatchToken());
                }
            } finally {
                parser.setContext(context);
            }
        }
        lexer.nextToken(16);
        parser.setContext(context);
        return map;
    }
    throw new JSONException("syntax error, expect {, actual " + lexer.tokenName());
}
项目:itmarry    文件:ASMDeserializerFactory.java   
private void _deserialze_obj(Context context, MethodVisitor mw, Label reset_, FieldInfo fieldInfo,
                             Class<?> fieldClass, int i) {
    Label matched_ = new Label();
    Label _end_if = new Label();

    mw.visitVarInsn(ALOAD, context.var("lexer"));
    mw.visitVarInsn(ALOAD, 0);
    mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_prefix__", "[C");
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(JSONLexerBase.class), "matchField", "([C)Z");
    mw.visitJumpInsn(IFNE, matched_);
    mw.visitInsn(ACONST_NULL);
    mw.visitVarInsn(ASTORE, context.var(fieldInfo.getName() + "_asm"));

    mw.visitJumpInsn(GOTO, _end_if);

    mw.visitLabel(matched_);

    _setFlag(mw, context, i);

    // increment matchedCount
    mw.visitVarInsn(ILOAD, context.var("matchedCount"));
    mw.visitInsn(ICONST_1);
    mw.visitInsn(IADD);
    mw.visitVarInsn(ISTORE, context.var("matchedCount"));

    _deserObject(context, mw, fieldInfo, fieldClass);

    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(DefaultJSONParser.class), "getResolveStatus", "()I");
    mw.visitFieldInsn(GETSTATIC, getType(DefaultJSONParser.class), "NeedToResolve", "I");
    mw.visitJumpInsn(IF_ICMPNE, _end_if);

    // ResolveTask task = parser.getLastResolveTask();
    // task.setFieldDeserializer(this);
    // task.setOwnerContext(parser.getContext());

    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(DefaultJSONParser.class), "getLastResolveTask",
                       "()" + getDesc(ResolveTask.class));
    mw.visitVarInsn(ASTORE, context.var("resolveTask"));

    mw.visitVarInsn(ALOAD, context.var("resolveTask"));
    mw.visitVarInsn(ALOAD, 1);
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(DefaultJSONParser.class), "getContext", "()"
                                                                                      + getDesc(ParseContext.class));
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(ResolveTask.class), "setOwnerContext", "("
                                                                                     + getDesc(ParseContext.class)
                                                                                     + ")V");

    mw.visitVarInsn(ALOAD, context.var("resolveTask"));
    mw.visitVarInsn(ALOAD, 0);
    mw.visitLdcInsn(fieldInfo.getName());
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(ASMJavaBeanDeserializer.class), "getFieldDeserializer",
                       "(Ljava/lang/String;)" + getDesc(FieldDeserializer.class));
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(ResolveTask.class), "setFieldDeserializer",
                       "(" + getDesc(FieldDeserializer.class) + ")V");

    mw.visitVarInsn(ALOAD, 1);
    mw.visitFieldInsn(GETSTATIC, getType(DefaultJSONParser.class), "NONE", "I");
    mw.visitMethodInsn(INVOKEVIRTUAL, getType(DefaultJSONParser.class), "setResolveStatus", "(I)V");

    mw.visitLabel(_end_if);

}