/src/main/java/com/alibaba/fastjson/parser/deserializer/BigIntegerDeserializer.java
Java | 41 lines | 31 code | 10 blank | 0 comment | 4 complexity | 5099c5c7bbd5ba6589009fae0bab7037 MD5 | raw file
- package com.alibaba.fastjson.parser.deserializer;
- import java.lang.reflect.Type;
- import java.math.BigInteger;
- 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 BigIntegerDeserializer implements ObjectDeserializer {
- public final static BigIntegerDeserializer instance = new BigIntegerDeserializer();
- @SuppressWarnings("unchecked")
- public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
- return (T) deserialze(parser);
- }
- @SuppressWarnings("unchecked")
- public static <T> T deserialze(DefaultJSONParser parser) {
- final JSONLexer lexer = parser.getLexer();
- if (lexer.token() == JSONToken.LITERAL_INT) {
- String val = lexer.numberString();
- lexer.nextToken(JSONToken.COMMA);
- return (T) new BigInteger(val);
- }
- Object value = parser.parse();
- if (value == null) {
- return null;
- }
- return (T) TypeUtils.castToBigInteger(value);
- }
- public int getFastMatchToken() {
- return JSONToken.LITERAL_INT;
- }
- }