Search in sources :

Example 6 with ResolveTask

use of com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask in project fastjson by alibaba.

the class DepartmentCodec method deserialze.

public Object deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
    if (lexer.isEnabled(Feature.SortFeidFastMatch)) {
        return super.deserialze(parser, type, fieldName);
    }
    if (lexer.isEnabled(Feature.SupportArrayToBean)) {
    // deserialzeArrayMapping
    }
    if (lexer.scanType("Department") == JSONLexerBase.NOT_MATCH) {
        return super.deserialze(parser, type, fieldName);
    }
    ParseContext mark_context = parser.getContext();
    int matchedCount = 0;
    Department instance = new Department();
    ParseContext context = parser.getContext();
    ParseContext childContext = parser.setContext(context, instance, fieldName);
    if (lexer.matchStat == JSONLexerBase.END) {
        return instance;
    }
    int matchStat = 0;
    int _asm_flag_0 = 0;
    int id_gen = 0;
    com.alibaba.json.test.codegen.Employee leader_gen = null;
    java.util.List members_gen = null;
    String name_gen;
    if (lexer.isEnabled(Feature.InitStringFieldAsEmpty)) {
        name_gen = lexer.stringDefaultValue();
        _asm_flag_0 |= 8;
    } else {
        name_gen = null;
    }
    boolean root_gen = false;
    com.alibaba.json.test.codegen.DepartmentType type_gen = null;
    boolean endFlag = false, restFlag = false;
    if ((!endFlag) && (!restFlag)) {
        id_gen = lexer.scanFieldInt(id_gen_prefix__);
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 1;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat == JSONLexerBase.END) {
            endFlag = true;
        }
    }
    if ((!endFlag) && (!restFlag)) {
        if (lexer.matchField(leader_gen_prefix__)) {
            _asm_flag_0 |= 2;
            matchedCount++;
            if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
                ResolveTask resolveTask = parser.getLastResolveTask();
                resolveTask.ownerContext = parser.getContext();
                resolveTask.fieldDeserializer = this.getFieldDeserializer("leader");
                parser.setResolveStatus(DefaultJSONParser.NONE);
            }
        }
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 2;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat == JSONLexerBase.END) {
            endFlag = true;
        }
    }
    if ((!endFlag) && (!restFlag)) {
        if (lexer.matchField(members_gen_prefix__)) {
            _asm_flag_0 |= 4;
            if (lexer.token() == JSONToken.NULL) {
                lexer.nextToken(JSONToken.COMMA);
            } else {
                if (lexer.token() == JSONToken.LBRACKET) {
                    if (members_gen_list_item_deser__ == null) {
                        members_gen_list_item_deser__ = parser.getConfig().getDeserializer(com.alibaba.json.test.codegen.Employee.class);
                    }
                    final int fastMatchToken = members_gen_list_item_deser__.getFastMatchToken();
                    lexer.nextToken(fastMatchToken);
                    members_gen = new java.util.ArrayList();
                    ParseContext listContext = parser.getContext();
                    parser.setContext(members_gen, "members");
                    for (int i = 0; ; ++i) {
                        if (lexer.token() == JSONToken.RBRACKET) {
                            break;
                        }
                        com.alibaba.json.test.codegen.Employee itemValue = members_gen_list_item_deser__.deserialze(parser, members_gen_list_item_type__, i);
                        members_gen.add(itemValue);
                        parser.checkListResolve(members_gen);
                        if (lexer.token() == JSONToken.COMMA) {
                            lexer.nextToken(fastMatchToken);
                        }
                    }
                    parser.setContext(listContext);
                    if (lexer.token() != JSONToken.RBRACKET) {
                        restFlag = true;
                    }
                    lexer.nextToken(JSONToken.COMMA);
                } else {
                    restFlag = true;
                }
            }
        }
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 4;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat == JSONLexerBase.END) {
            endFlag = true;
        }
    }
    if ((!endFlag) && (!restFlag)) {
        name_gen = lexer.scanFieldString(name_gen_prefix__);
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 8;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat == JSONLexerBase.END) {
            endFlag = true;
        }
    }
    if ((!endFlag) && (!restFlag)) {
        root_gen = lexer.scanFieldBoolean(root_gen_prefix__);
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 16;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat == JSONLexerBase.END) {
            endFlag = true;
        }
    }
    if ((!endFlag) && (!restFlag)) {
        type_gen = (com.alibaba.json.test.codegen.DepartmentType) this.scanEnum(lexer, type_gen_prefix__, type_gen_deser__);
        if (lexer.matchStat > 0) {
            _asm_flag_0 |= 32;
            matchedCount++;
        }
        if (lexer.matchStat == JSONLexerBase.NOT_MATCH) {
            restFlag = true;
        }
        if (lexer.matchStat != JSONLexerBase.END) {
            restFlag = true;
        }
    }
    if (restFlag) {
        return super.parseRest(parser, type, fieldName, instance, 0, new int[0]);
    }
    return instance;
}
Also used : JSONLexerBase(com.alibaba.fastjson.parser.JSONLexerBase) ParseContext(com.alibaba.fastjson.parser.ParseContext) ResolveTask(com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask)

Aggregations

ResolveTask (com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask)6 ParseContext (com.alibaba.fastjson.parser.ParseContext)5 JSONLexerBase (com.alibaba.fastjson.parser.JSONLexerBase)3 JSONException (com.alibaba.fastjson.JSONException)2 JSONObject (com.alibaba.fastjson.JSONObject)2 JSON (com.alibaba.fastjson.JSON)1 JSONField (com.alibaba.fastjson.annotation.JSONField)1 Label (com.alibaba.fastjson.asm.Label)1 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)1 FieldInfo (com.alibaba.fastjson.util.FieldInfo)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1