public void parseObject(DefaultJSONParser parser, Object object) {
Class<?> clazz = object.getClass();
Map<String, FieldDeserializer> setters = parser.getConfig().getFieldDeserializers(clazz);
JSONLexer lexer = parser.getLexer(); // xxx
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken(JSONToken.COMMA);
return;
}
if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
throw new JSONException("syntax error, expect {, actual " + lexer.tokenName());
}
final Object[] args = new Object[1];
for (;;) {
// lexer.scanSymbol
String key = lexer.scanSymbol(parser.getSymbolTable());
if (key == null) {
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken(JSONToken.COMMA);
break;
}
if (lexer.token() == JSONToken.COMMA) {
if (parser.isEnabled(Feature.AllowArbitraryCommas)) {
continue;
}
}
}
FieldDeserializer fieldDeser = setters.get(key);
if (fieldDeser == null) {
if (!parser.isEnabled(Feature.IgnoreNotMatch)) {
throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
}
lexer.nextTokenWithColon();
parser.parse(); // skip
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken();
return;
}
continue;
} else {
Method method = fieldDeser.getMethod();
Class<?> fieldClass = method.getParameterTypes()[0];
Type fieldType = method.getGenericParameterTypes()[0];
if (fieldClass == int.class) {
lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
args[0] = IntegerDeserializer.deserialze(parser);
} else if (fieldClass == String.class) {
lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
args[0] = StringDeserializer.deserialze(parser);
} else if (fieldClass == long.class) {
lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
args[0] = LongDeserializer.deserialze(parser);
} else if (fieldClass == List.class) {
lexer.nextTokenWithColon(JSONToken.LBRACE);
args[0] = CollectionDeserializer.instance.deserialze(parser, fieldType, null);
} else {
ObjectDeserializer fieldValueDeserializer = parser.getConfig().getDeserializer(fieldClass,
fieldType);
lexer.nextTokenWithColon(fieldValueDeserializer.getFastMatchToken());
args[0] = fieldValueDeserializer.deserialze(parser, fieldType, null);
}
try {
method.invoke(object, args);
} catch (Exception e) {
throw new JSONException("set proprety error, " + method.getName(), e);
}
}
if (lexer.token() == JSONToken.COMMA) {
continue;
}
if (lexer.token() == JSONToken.RBRACE) {
lexer.nextToken(JSONToken.COMMA);
return;
}
}
}