/src/main/java/com/alibaba/fastjson/parser/deserializer/ClassDerializer.java
Java | 40 lines | 29 code | 11 blank | 0 comment | 4 complexity | 91d30ee84bbe4b715a1d3c4b14945cec MD5 | raw file
- package com.alibaba.fastjson.parser.deserializer;
- import java.lang.reflect.Type;
- import com.alibaba.fastjson.JSONException;
- import com.alibaba.fastjson.parser.DefaultJSONParser;
- import com.alibaba.fastjson.parser.JSONLexer;
- import com.alibaba.fastjson.parser.JSONToken;
- import com.alibaba.fastjson.util.TypeUtils;
- public class ClassDerializer implements ObjectDeserializer {
- public final static ClassDerializer instance = new ClassDerializer();
- public ClassDerializer(){
- }
- @SuppressWarnings("unchecked")
- public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
- JSONLexer lexer = parser.getLexer();
-
- if (lexer.token() == JSONToken.NULL) {
- lexer.nextToken();
- return null;
- }
-
- if (lexer.token() != JSONToken.LITERAL_STRING) {
- throw new JSONException("expect className");
- }
- String className = lexer.stringVal();
- lexer.nextToken(JSONToken.COMMA);
- return (T) TypeUtils.loadClass(className);
- }
- public int getFastMatchToken() {
- return JSONToken.LITERAL_STRING;
- }
- }