PageRenderTime 324ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/xiejuntao/xdesktop
Java | 41 lines | 31 code | 10 blank | 0 comment | 4 complexity | 5099c5c7bbd5ba6589009fae0bab7037 MD5 | raw file
  1. package com.alibaba.fastjson.parser.deserializer;
  2. import java.lang.reflect.Type;
  3. import java.math.BigInteger;
  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 BigIntegerDeserializer implements ObjectDeserializer {
  9. public final static BigIntegerDeserializer instance = new BigIntegerDeserializer();
  10. @SuppressWarnings("unchecked")
  11. public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
  12. return (T) deserialze(parser);
  13. }
  14. @SuppressWarnings("unchecked")
  15. public static <T> T deserialze(DefaultJSONParser parser) {
  16. final JSONLexer lexer = parser.getLexer();
  17. if (lexer.token() == JSONToken.LITERAL_INT) {
  18. String val = lexer.numberString();
  19. lexer.nextToken(JSONToken.COMMA);
  20. return (T) new BigInteger(val);
  21. }
  22. Object value = parser.parse();
  23. if (value == null) {
  24. return null;
  25. }
  26. return (T) TypeUtils.castToBigInteger(value);
  27. }
  28. public int getFastMatchToken() {
  29. return JSONToken.LITERAL_INT;
  30. }
  31. }