本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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));
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}