当前位置: 首页>>代码示例>>Java>>正文


Java DefaultJSONParser类代码示例

本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser类的具体用法?Java DefaultJSONParser怎么用?Java DefaultJSONParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultJSONParser类属于com.alibaba.fastjson.parser包,在下文中一共展示了DefaultJSONParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseArray

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:JSON.java

示例2: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object deserialze(DefaultJSONParser parser, Type type, Object fieldName, Map map) {
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type keyType = parameterizedType.getActualTypeArguments()[0];
        Type valueType = parameterizedType.getActualTypeArguments()[1];

        if (String.class == keyType) {
            return parseMap(parser, (Map<String, Object>) map, valueType, fieldName);
        } else {
            return parseMap(parser, map, keyType, valueType, fieldName);
        }
    } else {
        return parser.parseObject(map, fieldName);
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:17,代码来源:MapDeserializer.java

示例3: parseArray

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
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;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:24,代码来源:JSON.java

示例4: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
@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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:CalendarCodec.java

示例5: parseField

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
    if (fieldValueDeserilizer == null) {
        fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
    }

    if (objectType instanceof ParameterizedType) {
        ParseContext objContext = parser.getContext();
        objContext.setType(objectType);
    }

    Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
    if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
        ResolveTask task = parser.getLastResolveTask();
        task.setFieldDeserializer(this);
        task.setOwnerContext(parser.getContext());
        parser.setResolveStatus(DefaultJSONParser.NONE);
    } else {
        if (object == null) {
            fieldValues.put(fieldInfo.getName(), value);
        } else {
            setValue(object, value);
        }
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:26,代码来源:DefaultFieldDeserializer.java

示例6: test_0

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_0() throws Exception {
    List<?> res = Arrays.asList(1, 2, 3);
    String[] tests = { "[1,2,3]", "[1,,2,3]", "[1,2,,,3]", "[1 2,,,3]", "[1 2 3]", "[1, 2, 3,,]", "[,,1, 2, 3,,]", };

    for (String t : tests) {
        DefaultJSONParser ext = new DefaultJSONParser(t);
        ext.config(Feature.AllowArbitraryCommas, true);
        List<Object> extRes = ext.parseArray(Object.class);
        Assert.assertEquals(res, extRes);

        DefaultJSONParser basic = new DefaultJSONParser(t);
        basic.config(Feature.AllowArbitraryCommas, true);
        List<Object> basicRes = new ArrayList<Object>();
        basic.parseArray(basicRes);
        Assert.assertEquals(res, basicRes);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DefaultExtJSONParserTest_4.java

示例7: parseArray

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:JSON.java

示例8: test_scanFloat

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_scanFloat() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 1024; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        buf.append("{\"id\":" + i + ".0}");
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    List<VO> array = parser.parseArray(VO.class);
    for (int i = 0; i < array.size(); ++i) {
        Assert.assertTrue(Integer.toString(i), (double) i == array.get(i).getId());
    }
    parser.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:JSONReaderScannerTest__entity_double_2.java

示例9: test_scanInt

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_scanInt() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 1024; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        buf.append(i + ".0");
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    JSONArray array = (JSONArray) parser.parse();
    for (int i = 0; i < array.size(); ++i) {
        BigDecimal value = new BigDecimal(i + ".0");
        Assert.assertEquals(value, array.get(i));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:JSONReaderScannerTest_decimal.java

示例10: parseObject

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static final <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

    for (Feature featrue : features) {
        featureValues = Feature.config(featureValues, featrue, true);
    }

    DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
    T value = (T) parser.parseObject(clazz);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:20,代码来源:JSON.java

示例11: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
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);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:FloatCodec.java

示例12: test_1

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_1() throws Exception {
    String input = "{,,,\"value\":null,\"id\":123,,,,}";
    int featureValues = 0;
    featureValues |= Feature.AllowArbitraryCommas.getMask();
    featureValues |= Feature.IgnoreNotMatch.getMask();
    DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
    
    Entity object = new Entity();
    parser.parseObject(object);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:FieldDeserializerTest2.java

示例13: test_parse

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_parse() throws Exception {
    DefaultJSONParser parser = new DefaultJSONParser("1");
    Assert.assertEquals(Integer.valueOf(1), parser.parse());

    Exception error = null;
    try {
        parser.parse();
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:DefaultExtJSONParserTest_7.java

示例14: test_date_2

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
public void test_date_2() throws Exception {
    int features = JSON.DEFAULT_PARSER_FEATURE;
    DefaultJSONParser parser = new DefaultJSONParser("new Date(1294552193254)", ParserConfig.getGlobalInstance(), features);

    java.sql.Date date = parser.parseObject(java.sql.Date.class);

    Assert.assertEquals(new java.sql.Date(1294552193254L), date);
    parser.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:DateParserTest_sql.java

示例15: deserialze

import com.alibaba.fastjson.parser.DefaultJSONParser; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    if (type instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType) type).getGenericComponentType();
        if (componentType instanceof TypeVariable) {
            TypeVariable<?> componentVar = (TypeVariable<?>) componentType;
            componentType = componentVar.getBounds()[0];
        }

        List<Object> list = new ArrayList<Object>();
        parser.parseArray(componentType, list);
        Class<?> componentClass;
        if (componentType instanceof Class) {
            componentClass = (Class<?>) componentType;
            Object[] array = (Object[]) Array.newInstance(componentClass, list.size());
            list.toArray(array);
            return (T) array;
        } else {
            return (T) list.toArray();
        }

    }
    
    if (type instanceof Class && type != Object.class && type != Serializable.class) {
        return (T) parser.parseObject(type);    
    }

    return (T) parser.parse(fieldName);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:JavaObjectDeserializer.java


注:本文中的com.alibaba.fastjson.parser.DefaultJSONParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。