Java 类com.alibaba.fastjson.parser.JSONLexer 实例源码

项目:GitHub    文件:ArrayListTypeFieldDeserializer.java   
@SuppressWarnings("rawtypes")
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    JSONLexer lexer = parser.lexer;
    final int token = lexer.token();
    if (token == JSONToken.NULL
            || (token == JSONToken.LITERAL_STRING && lexer.stringVal().length() == 0)) {
        setValue(object, null);
        return;
    }

    ArrayList list = new ArrayList();

    ParseContext context = parser.getContext();

    parser.setContext(context, object, fieldInfo.name);
    parseArray(parser, objectType, list);
    parser.setContext(context);

    if (object == null) {
        fieldValues.put(fieldInfo.name, list);
    } else {
        setValue(object, list);
    }
}
项目:GitHub    文件:JavaBeanDeserializer.java   
protected Enum scanEnum(JSONLexerBase lexer, char[] name_chars, ObjectDeserializer fieldValueDeserilizer) {
    EnumDeserializer enumDeserializer = null;
    if (fieldValueDeserilizer instanceof EnumDeserializer) {
        enumDeserializer = (EnumDeserializer) fieldValueDeserilizer;
    }

    if (enumDeserializer == null) {
        lexer.matchStat = JSONLexer.NOT_MATCH;
        return null;
    }

    long enumNameHashCode = lexer.scanFieldSymbol(name_chars);
    if (lexer.matchStat > 0) {
        return enumDeserializer.getEnumByHashCode(enumNameHashCode);
    } else {
        return null;
    }
}
项目:GitHub    文件:JSONReader.java   
public String readString() {
    Object object;
    if (context == null) {
        object = parser.parse();
    } else {
        readBefore();
        JSONLexer lexer = parser.lexer;
        if (context.state == JSONStreamContext.StartObject && lexer.token() == JSONToken.IDENTIFIER) {
            object = lexer.stringVal();
            lexer.nextToken();
        } else {
            object = parser.parse();
        }
        readAfter();
    }

    return TypeUtils.castToString(object);
}
项目:GitHub    文件:CalendarCodec.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    Object value = DateCodec.instance.deserialze(parser, type, fieldName);

    if (value instanceof Calendar) {
        return (T) value;
    }

    Date date = (Date) value;
    if (date == null) {
        return null;
    }

    JSONLexer lexer = parser.lexer;
    Calendar calendar = Calendar.getInstance(lexer.getTimeZone(), lexer.getLocale());
    calendar.setTime(date);

    if (type == XMLGregorianCalendar.class) {
        return (T) createXMLGregorianCalendar((GregorianCalendar) calendar);
    }

    return (T) calendar;
}
项目:GitHub    文件:BigDecimalCodec.java   
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
    final JSONLexer lexer = parser.lexer;
    if (lexer.token() == JSONToken.LITERAL_INT) {
        BigDecimal decimalValue = lexer.decimalValue();
        lexer.nextToken(JSONToken.COMMA);
        return (T) decimalValue;
    }

    if (lexer.token() == JSONToken.LITERAL_FLOAT) {
        BigDecimal val = lexer.decimalValue();
        lexer.nextToken(JSONToken.COMMA);
        return (T) val;
    }

    Object value = parser.parse();
    return value == null //
        ? null //
        : (T) TypeUtils.castToBigDecimal(value);
}
项目:GitHub    文件:JSON.java   
public static JSONArray parseArray(String text) {
    if (text == null) {
        return null;
    }

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());

    JSONArray array;

    JSONLexer lexer = parser.lexer;
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken();
        array = null;
    } else if (lexer.token() == JSONToken.EOF) {
        array = null;
    } else {
        array = new JSONArray();
        parser.parseArray(array);

        parser.handleResovleTask(array);
    }

    parser.close();

    return array;
}
项目:GitHub    文件:JSON.java   
public static <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
        return null;
    }

    List<T> list;

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.lexer;
    int token = lexer.token();
    if (token == JSONToken.NULL) {
        lexer.nextToken();
        list = null;
    } else if (token == JSONToken.EOF && lexer.isBlankInput()) {
        list = null;
    } else {
        list = new ArrayList<T>();
        parser.parseArray(clazz, list);

        parser.handleResovleTask(list);
    }

    parser.close();

    return list;
}
项目:GitHub    文件:ImageDeserializer.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    Image image = new Image();

    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() != JSONToken.LBRACKET) {
        throw new JSONException("error");
    }

    int height = lexer.scanInt(',');
    int width = lexer.scanInt(',');
    String sizeName = lexer.scanSymbolWithSeperator(parser.getSymbolTable(), ',');
    String title = lexer.scanString(',');
    String uri = lexer.scanString(']');

    lexer.nextToken(JSONToken.COMMA);

    image.setHeight(height);
    image.setWidth(width);
    image.setSize(Size.valueOf(sizeName));
    image.setTitle(title);
    image.setUri(uri);
    return (T) image;
}
项目:WeiMusicCommunity-server    文件:JodaTimeDeserializer.java   
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.LITERAL_STRING) {
        String text = lexer.stringVal();
        lexer.nextToken();
        if (type == LocalDateTime.class) {
            return (T) LocalDateTime.parse(text);
        } else if (type == LocalDate.class) {
            return (T) LocalDate.parse(text);
        } else if (type == LocalTime.class) {
            return (T) LocalTime.parse(text);
        } else if (type == Period.class) {
            return (T) Period.parse(text);
        } else if (type == Duration.class) {
            return (T) Duration.parse(text);
        } else if (type == Instant.class) {
            return (T) Instant.parse(text);
        }
    } else {
        throw new UnsupportedOperationException();
    }
    return null;
}
项目:boohee_v5.6    文件:CharArrayDeserializer.java   
public static <T> T deserialze(DefaultJSONParser parser) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 4) {
        String val = lexer.stringVal();
        lexer.nextToken(16);
        return val.toCharArray();
    } else if (lexer.token() == 2) {
        Number val2 = lexer.integerValue();
        lexer.nextToken(16);
        return val2.toString().toCharArray();
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        return JSON.toJSONString(value).toCharArray();
    }
}
项目:boohee_v5.6    文件:StringFieldDeserializer.java   
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    String value;
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 4) {
        value = lexer.stringVal();
        lexer.nextToken(16);
    } else {
        Object obj = parser.parse();
        if (obj == null) {
            value = null;
        } else {
            value = obj.toString();
        }
    }
    if (object == null) {
        fieldValues.put(this.fieldInfo.getName(), value);
    } else {
        setValue(object, value);
    }
}
项目:boohee_v5.6    文件:JavaBeanDeserializer.java   
public boolean parseField(DefaultJSONParser parser, String key, Object object, Type objectType, Map<String, Object> fieldValues) {
    JSONLexer lexer = parser.getLexer();
    FieldDeserializer fieldDeserializer = (FieldDeserializer) this.feildDeserializerMap.get(key);
    if (fieldDeserializer == null) {
        for (Entry<String, FieldDeserializer> entry : this.feildDeserializerMap.entrySet()) {
            if (((String) entry.getKey()).equalsIgnoreCase(key)) {
                fieldDeserializer = (FieldDeserializer) entry.getValue();
                break;
            }
        }
    }
    if (fieldDeserializer == null) {
        parseExtra(parser, object, key);
        return false;
    }
    lexer.nextTokenWithColon(fieldDeserializer.getFastMatchToken());
    fieldDeserializer.parseField(parser, object, objectType, fieldValues);
    return true;
}
项目:boohee_v5.6    文件:JavaBeanDeserializer.java   
void parseExtra(DefaultJSONParser parser, Object object, String key) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.isEnabled(Feature.IgnoreNotMatch)) {
        Object value;
        lexer.nextTokenWithColon();
        Type type = FilterUtils.getExtratype(parser, object, key);
        if (type == null) {
            value = parser.parse();
        } else {
            value = parser.parseObject(type);
        }
        FilterUtils.processExtra(parser, object, key, value);
        return;
    }
    throw new JSONException("setter not found, class " + this.clazz.getName() + ", property " + key);
}
项目:boohee_v5.6    文件:ASMJavaBeanDeserializer.java   
public boolean parseField(DefaultJSONParser parser, String key, Object object, Type objectType, Map<String, Object> fieldValues) {
    JSONLexer lexer = parser.getLexer();
    Map<String, FieldDeserializer> feildDeserializerMap = this.serializer.getFieldDeserializerMap();
    FieldDeserializer fieldDeserializer = (FieldDeserializer) feildDeserializerMap.get(key);
    if (fieldDeserializer == null) {
        for (Entry<String, FieldDeserializer> entry : feildDeserializerMap.entrySet()) {
            if (((String) entry.getKey()).equalsIgnoreCase(key)) {
                fieldDeserializer = (FieldDeserializer) entry.getValue();
                break;
            }
        }
    }
    if (fieldDeserializer == null) {
        this.serializer.parseExtra(parser, object, key);
        return false;
    }
    lexer.nextTokenWithColon(fieldDeserializer.getFastMatchToken());
    fieldDeserializer.parseField(parser, object, objectType, fieldValues);
    return true;
}
项目:boohee_v5.6    文件:IntegerCodec.java   
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken(16);
        return null;
    }
    T intObj;
    if (lexer.token() == 2) {
        int val = lexer.intValue();
        lexer.nextToken(16);
        intObj = Integer.valueOf(val);
    } else if (lexer.token() == 3) {
        BigDecimal decimalValue = lexer.decimalValue();
        lexer.nextToken(16);
        intObj = Integer.valueOf(decimalValue.intValue());
    } else {
        intObj = TypeUtils.castToInt(parser.parse());
    }
    if (clazz == AtomicInteger.class) {
        return new AtomicInteger(intObj.intValue());
    }
    return intObj;
}
项目:boohee_v5.6    文件:FloatCodec.java   
public static <T> T deserialze(DefaultJSONParser parser) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 2) {
        String val = lexer.numberString();
        lexer.nextToken(16);
        return Float.valueOf(Float.parseFloat(val));
    } else if (lexer.token() == 3) {
        float val2 = lexer.floatValue();
        lexer.nextToken(16);
        return Float.valueOf(val2);
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        return TypeUtils.castToFloat(value);
    }
}
项目:boohee_v5.6    文件:LongCodec.java   
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    Long longObject;
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 2) {
        long longValue = lexer.longValue();
        lexer.nextToken(16);
        longObject = Long.valueOf(longValue);
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        longObject = TypeUtils.castToLong(value);
    }
    if (clazz == AtomicLong.class) {
        return new AtomicLong(longObject.longValue());
    }
    return longObject;
}
项目:boohee_v5.6    文件:BigDecimalCodec.java   
public static <T> T deserialze(DefaultJSONParser parser) {
    JSONLexer lexer = parser.getLexer();
    long val;
    if (lexer.token() == 2) {
        val = lexer.longValue();
        lexer.nextToken(16);
        return new BigDecimal(val);
    } else if (lexer.token() == 3) {
        val = lexer.decimalValue();
        lexer.nextToken(16);
        return val;
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        return TypeUtils.castToBigDecimal(value);
    }
}
项目:boohee_v5.6    文件:StringCodec.java   
public static <T> T deserialze(DefaultJSONParser parser) {
    JSONLexer lexer = parser.getLexer();
    String val;
    if (lexer.token() == 4) {
        val = lexer.stringVal();
        lexer.nextToken(16);
        return val;
    } else if (lexer.token() == 2) {
        val = lexer.numberString();
        lexer.nextToken(16);
        return val;
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        return value.toString();
    }
}
项目:boohee_v5.6    文件:JSON.java   
public static final JSONArray parseArray(String text) {
    if (text == null) {
        return null;
    }
    JSONArray array;
    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken();
        array = null;
    } else if (lexer.token() == 20) {
        array = null;
    } else {
        Collection array2 = new JSONArray();
        parser.parseArray(array2);
        parser.handleResovleTask(array2);
    }
    parser.close();
    return array;
}
项目:boohee_v5.6    文件:JSON.java   
public static final <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
        return null;
    }
    List<T> list;
    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken();
        list = null;
    } else {
        Collection list2 = new ArrayList();
        parser.parseArray((Class) clazz, list2);
        parser.handleResovleTask(list2);
    }
    parser.close();
    return list;
}
项目:boohee_v5.6    文件:ASMUtils.java   
public static void parseArray(Collection collection, ObjectDeserializer deser, DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 8) {
        lexer.nextToken(16);
    }
    parser.accept(14, 14);
    int index = 0;
    while (true) {
        collection.add(deser.deserialze(parser, type, Integer.valueOf(index)));
        index++;
        if (lexer.token() == 16) {
            lexer.nextToken(14);
        } else {
            parser.accept(15, 16);
            return;
        }
    }
}
项目:uavstack    文件:MapDeserializer.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken(JSONToken.COMMA);
        return null;
    }

    Map<Object, Object> map = createMap(type);

    ParseContext context = parser.getContext();

    try {
        parser.setContext(context, map, fieldName);
        return (T) deserialze(parser, type, fieldName, map);
    } finally {
        parser.setContext(context);
    }
}
项目:uavstack    文件:StringFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    String value;

    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.LITERAL_STRING) {
        value = lexer.stringVal();
        lexer.nextToken(JSONToken.COMMA);
    } else {

        Object obj = parser.parse();

        if (obj == null) {
            value = null;
        } else {
            value = obj.toString();
        }
    }

    if (object == null) {
        fieldValues.put(fieldInfo.getName(), value);
    } else {
        setValue(object, value);
    }
}
项目:uavstack    文件:ClassDerializer.java   
@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);
}
项目:uavstack    文件:JavaBeanDeserializer.java   
void parseExtra(DefaultJSONParser parser, Object object, String key) {
    final JSONLexer lexer = parser.getLexer(); // xxx
    if (!lexer.isEnabled(Feature.IgnoreNotMatch)) {
        throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
    }

    lexer.nextTokenWithColon();
    Type type = FilterUtils.getExtratype(parser, object, key);
    Object value;
    if (type == null) {
        value = parser.parse(); // skip
    } else {
        value = parser.parseObject(type);
    }

    FilterUtils.processExtra(parser, object, key, value);
}
项目:uavstack    文件:ASMJavaBeanDeserializer.java   
public boolean parseField(DefaultJSONParser parser, String key, Object object, Type objectType,
                          Map<String, Object> fieldValues) {
    JSONLexer lexer = parser.getLexer(); // xxx

    Map<String, FieldDeserializer> feildDeserializerMap = serializer.getFieldDeserializerMap();
    FieldDeserializer fieldDeserializer = feildDeserializerMap.get(key);

    if (fieldDeserializer == null) {
        for (Map.Entry<String, FieldDeserializer> entry : feildDeserializerMap.entrySet()) {
            if (entry.getKey().equalsIgnoreCase(key)) {
                fieldDeserializer = entry.getValue();
                break;
            }
        }
    }

    if (fieldDeserializer == null) {
        this.serializer.parseExtra(parser, object, key);
        return false;
    }

    lexer.nextTokenWithColon(fieldDeserializer.getFastMatchToken());
    fieldDeserializer.parseField(parser, object, objectType, fieldValues);
    return true;
}
项目:uavstack    文件:BigIntegerCodec.java   
@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);
}
项目:uavstack    文件:LongCodec.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    final JSONLexer lexer = parser.getLexer();

    Long longObject;
    if (lexer.token() == JSONToken.LITERAL_INT) {
        long longValue = lexer.longValue();
        lexer.nextToken(JSONToken.COMMA);
        longObject = Long.valueOf(longValue);
    } else {

        Object value = parser.parse();

        if (value == null) {
            return null;
        }

        longObject = TypeUtils.castToLong(value);
    }

    if (clazz == AtomicLong.class) {
        return (T) new AtomicLong(longObject.longValue());
    }

    return (T) longObject;
}
项目:uavstack    文件:JSON.java   
public static final JSONArray parseArray(String text) {
    if (text == null) {
        return null;
    }

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());

    JSONArray array;

    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken();
        array = null;
    } else if (lexer.token() == JSONToken.EOF) {
        array = null;
    } else {
        array = new JSONArray();
        parser.parseArray(array);

        parser.handleResovleTask(array);
    }

    parser.close();

    return array;
}
项目:uavstack    文件:JSON.java   
public static final <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
        return null;
    }

    List<T> list;

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken();
        list = null;
    } else {
        list = new ArrayList<T>();
        parser.parseArray(clazz, list);

        parser.handleResovleTask(list);
    }

    parser.close();

    return list;
}
项目:itmarry    文件:MapDeserializer.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken(JSONToken.COMMA);
        return null;
    }

    Map<Object, Object> map = createMap(type);

    ParseContext context = parser.getContext();

    try {
        parser.setContext(context, map, fieldName);
        return (T) deserialze(parser, type, fieldName, map);
    } finally {
        parser.setContext(context);
    }
}
项目:itmarry    文件:StringFieldDeserializer.java   
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    String value;

    final JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.LITERAL_STRING) {
        value = lexer.stringVal();
        lexer.nextToken(JSONToken.COMMA);
    } else {

        Object obj = parser.parse();

        if (obj == null) {
            value = null;
        } else {
            value = obj.toString();
        }
    }

    if (object == null) {
        fieldValues.put(fieldInfo.getName(), value);
    } else {
        setValue(object, value);
    }
}
项目:itmarry    文件:ClassDerializer.java   
@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);
}
项目:itmarry    文件:JavaBeanDeserializer.java   
void parseExtra(DefaultJSONParser parser, Object object, String key) {
    final JSONLexer lexer = parser.getLexer(); // xxx
    if (!lexer.isEnabled(Feature.IgnoreNotMatch)) {
        throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
    }

    lexer.nextTokenWithColon();
    Type type = FilterUtils.getExtratype(parser, object, key);
    Object value;
    if (type == null) {
        value = parser.parse(); // skip
    } else {
        value = parser.parseObject(type);
    }

    FilterUtils.processExtra(parser, object, key, value);
}
项目:itmarry    文件:ASMJavaBeanDeserializer.java   
public boolean parseField(DefaultJSONParser parser, String key, Object object, Type objectType,
                          Map<String, Object> fieldValues) {
    JSONLexer lexer = parser.getLexer(); // xxx

    Map<String, FieldDeserializer> feildDeserializerMap = serializer.getFieldDeserializerMap();
    FieldDeserializer fieldDeserializer = feildDeserializerMap.get(key);

    if (fieldDeserializer == null) {
        for (Map.Entry<String, FieldDeserializer> entry : feildDeserializerMap.entrySet()) {
            if (entry.getKey().equalsIgnoreCase(key)) {
                fieldDeserializer = entry.getValue();
                break;
            }
        }
    }

    if (fieldDeserializer == null) {
        this.serializer.parseExtra(parser, object, key);
        return false;
    }

    lexer.nextTokenWithColon(fieldDeserializer.getFastMatchToken());
    fieldDeserializer.parseField(parser, object, objectType, fieldValues);
    return true;
}
项目:itmarry    文件:BigIntegerCodec.java   
@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);
}
项目:itmarry    文件:LongCodec.java   
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    final JSONLexer lexer = parser.getLexer();

    Long longObject;
    if (lexer.token() == JSONToken.LITERAL_INT) {
        long longValue = lexer.longValue();
        lexer.nextToken(JSONToken.COMMA);
        longObject = Long.valueOf(longValue);
    } else {

        Object value = parser.parse();

        if (value == null) {
            return null;
        }

        longObject = TypeUtils.castToLong(value);
    }

    if (clazz == AtomicLong.class) {
        return (T) new AtomicLong(longObject.longValue());
    }

    return (T) longObject;
}
项目:itmarry    文件:JSON.java   
public static final JSONArray parseArray(String text) {
    if (text == null) {
        return null;
    }

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());

    JSONArray array;

    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken();
        array = null;
    } else if (lexer.token() == JSONToken.EOF) {
        array = null;
    } else {
        array = new JSONArray();
        parser.parseArray(array);

        handleResovleTask(parser, array);
    }

    parser.close();

    return array;
}
项目:itmarry    文件:JSON.java   
public static final <T> List<T> parseArray(String text, Class<T> clazz) {
    if (text == null) {
        return null;
    }

    List<T> list;

    DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == JSONToken.NULL) {
        lexer.nextToken();
        list = null;
    } else {
        list = new ArrayList<T>();
        parser.parseArray(clazz, list);

        handleResovleTask(parser, list);
    }

    parser.close();

    return list;
}