@SuppressWarnings({"unchecked", "rawtypes"}) public void parseArray(Type type, Collection array, Object fieldName) { if (lexer.token() == JSONToken.SET || lexer.token() == JSONToken.TREE_SET) { lexer.nextToken(); } if (lexer.token() != JSONToken.LBRACKET) { throw new JSONException("exepct '[', but " + JSONToken.name(lexer.token())); } ObjectDeserializer deserializer = null; if (int.class == type) { deserializer = IntegerDeserializer.instance; lexer.nextToken(JSONToken.LITERAL_INT); } else if (String.class == type) { deserializer = StringDeserializer.instance; lexer.nextToken(JSONToken.LITERAL_STRING); } else { deserializer = config.getDeserializer(type); lexer.nextToken(deserializer.getFastMatchToken()); } ParseContext context = this.getContext(); this.setContext(array, fieldName); try { for (int i = 0; ; ++i) { if (isEnabled(Feature.AllowArbitraryCommas)) { while (lexer.token() == JSONToken.COMMA) { lexer.nextToken(); continue; } } if (lexer.token() == JSONToken.RBRACKET) { break; } if (int.class == type) { Object val = IntegerDeserializer.instance.deserialze(this, null, null); array.add(val); } else if (String.class == type) { String value; if (lexer.token() == JSONToken.LITERAL_STRING) { value = lexer.stringVal(); lexer.nextToken(JSONToken.COMMA); } else { Object obj = this.parse(); if (obj == null) { value = null; } else { value = obj.toString(); } } array.add(value); } else { Object val; if (lexer.token() == JSONToken.NULL) { lexer.nextToken(); val = null; } else { val = deserializer.deserialze(this, type, i); } array.add(val); checkListResolve(array); } if (lexer.token() == JSONToken.COMMA) { lexer.nextToken(deserializer.getFastMatchToken()); continue; } } } finally { this.setContext(context); } lexer.nextToken(JSONToken.COMMA); }
@SuppressWarnings({"unchecked", "rawtypes"}) public final void parseArray(final Collection array, Object fieldName) { final JSONLexer lexer = getLexer(); if (lexer.token() == JSONToken.SET || lexer.token() == JSONToken.TREE_SET) { lexer.nextToken(); } if (lexer.token() != JSONToken.LBRACKET) { throw new JSONException( "syntax error, expect [, actual " + JSONToken.name(lexer.token()) + ", pos " + lexer.pos()); } lexer.nextToken(JSONToken.LITERAL_STRING); ParseContext context = this.getContext(); this.setContext(array, fieldName); try { for (int i = 0; ; ++i) { if (isEnabled(Feature.AllowArbitraryCommas)) { while (lexer.token() == JSONToken.COMMA) { lexer.nextToken(); continue; } } Object value; switch (lexer.token()) { case LITERAL_INT: value = lexer.integerValue(); lexer.nextToken(JSONToken.COMMA); break; case LITERAL_FLOAT: if (lexer.isEnabled(Feature.UseBigDecimal)) { value = lexer.decimalValue(true); } else { value = lexer.decimalValue(false); } lexer.nextToken(JSONToken.COMMA); break; case LITERAL_STRING: String stringLiteral = lexer.stringVal(); lexer.nextToken(JSONToken.COMMA); if (lexer.isEnabled(Feature.AllowISO8601DateFormat)) { JSONScanner iso8601Lexer = new JSONScanner(stringLiteral); if (iso8601Lexer.scanISO8601DateIfMatch()) { value = iso8601Lexer.getCalendar().getTime(); } else { value = stringLiteral; } iso8601Lexer.close(); } else { value = stringLiteral; } break; case TRUE: value = Boolean.TRUE; lexer.nextToken(JSONToken.COMMA); break; case FALSE: value = Boolean.FALSE; lexer.nextToken(JSONToken.COMMA); break; case LBRACE: JSONObject object = new JSONObject(); value = parseObject(object, i); break; case LBRACKET: Collection items = new JSONArray(); parseArray(items, i); value = items; break; case NULL: value = null; lexer.nextToken(JSONToken.LITERAL_STRING); break; case RBRACKET: lexer.nextToken(JSONToken.COMMA); return; case EOF: throw new JSONException("unclosed jsonArray"); default: value = parse(); break; } array.add(value); checkListResolve(array); if (lexer.token() == JSONToken.COMMA) { lexer.nextToken(JSONToken.LITERAL_STRING); continue; } } } finally { this.setContext(context); } }
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 (isSupportArrayToBean(lexer)) { // 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)) { String type_gen_enum_name = lexer.scanFieldSymbol(type_gen_prefix__, parser.getSymbolTable()); if (type_gen_enum_name == null) { type_gen = com.alibaba.json.test.codegen.DepartmentType.valueOf(type_gen_enum_name); } 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); } return instance; }