PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/alibaba/fastjson/parser/deserializer/ClassDerializer.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 40 lines | 29 code | 11 blank | 0 comment | 4 complexity | 91d30ee84bbe4b715a1d3c4b14945cec MD5 | raw file
  1. package com.alibaba.fastjson.parser.deserializer;
  2. import java.lang.reflect.Type;
  3. import com.alibaba.fastjson.JSONException;
  4. import com.alibaba.fastjson.parser.DefaultJSONParser;
  5. import com.alibaba.fastjson.parser.JSONLexer;
  6. import com.alibaba.fastjson.parser.JSONToken;
  7. import com.alibaba.fastjson.util.TypeUtils;
  8. public class ClassDerializer implements ObjectDeserializer {
  9. public final static ClassDerializer instance = new ClassDerializer();
  10. public ClassDerializer(){
  11. }
  12. @SuppressWarnings("unchecked")
  13. public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
  14. JSONLexer lexer = parser.getLexer();
  15. if (lexer.token() == JSONToken.NULL) {
  16. lexer.nextToken();
  17. return null;
  18. }
  19. if (lexer.token() != JSONToken.LITERAL_STRING) {
  20. throw new JSONException("expect className");
  21. }
  22. String className = lexer.stringVal();
  23. lexer.nextToken(JSONToken.COMMA);
  24. return (T) TypeUtils.loadClass(className);
  25. }
  26. public int getFastMatchToken() {
  27. return JSONToken.LITERAL_STRING;
  28. }
  29. }