本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.parseObject方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.parseObject方法的具体用法?Java DefaultJSONParser.parseObject怎么用?Java DefaultJSONParser.parseObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.parseObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_2
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_2() throws Exception {
A res = new A();
res.setA(1);
res.setB(2);
res.setC(3);
String[] tests = { "{ 'a':1, 'b':2, 'c':3 }", "{ 'a':1,,'b':2, 'c':3 }", "{,'a':1, 'b':2, 'c':3 }", "{'a':1, 'b':2, 'c':3,,}",
"{,,'a':1,,,,'b':2,,'c':3,,,,,}", };
for (String t : tests) {
DefaultJSONParser ext = new DefaultJSONParser(t);
ext.config(Feature.AllowArbitraryCommas, true);
A extRes = ext.parseObject(A.class);
Assert.assertEquals(res, extRes);
}
}
示例2: 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);
}
示例3: test_error_2
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_2() throws Exception {
Exception error = null;
try {
String input = "{,,\"value\":null}";
int featureValues = 0;
DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(),
featureValues);
Entity object = new Entity();
parser.parseObject(object);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例4: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Integer intValue = parser.parseObject(int.class);
if (intValue == 1) {
return (T) OrderActionEnum.FAIL;
} else if (intValue == 0) {
return (T) OrderActionEnum.SUCC;
}
throw new IllegalStateException();
}
示例5: test_error_3
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_3() {
String text = "{\"obj\":true]}";
char[] chars = text.toCharArray();
DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
JSONException error = null;
try {
parser.parseObject();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例6: 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);
}
示例7: test_4
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_4() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("{v5:'3'}");
parser.config(Feature.AllowUnQuotedFieldNames, true);
parser.config(Feature.AllowSingleQuotes, true);
A a = parser.parseObject(A.class);
Assert.assertEquals(3L, a.getV5().longValue());
}
示例8: test_error_1
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_1() throws Exception {
Exception error = null;
try {
String input = "{\"value\":null}";
int featureValues = 0;
DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(),
featureValues);
Entity object = new Entity();
parser.parseObject(object);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例9: test_error_2
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_2() throws Exception {
Exception error = null;
try {
String text = "4";
DefaultJSONParser parser = new DefaultJSONParser(text);
parser.parseObject(TypeA.class);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例10: test_error_3
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_3() throws Exception {
JSONException error = null;
try {
DefaultJSONParser parser = new DefaultJSONParser("{");
parser.config(Feature.AllowUnQuotedFieldNames, true);
parser.parseObject(A.class);
} catch (JSONException e) {
error = e;
}
Assert.assertNotNull(error);
}
示例11: 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.Timestamp date = parser.parseObject(java.sql.Timestamp.class);
Assert.assertEquals(new java.sql.Timestamp(1294552193254L), date);
parser.close();
}
示例12: test_reader
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_reader() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"date\":\"2012/04-01\"}", 0));
parser.setDateFormat("yyyy/MM-dd");
VO vo = parser.parseObject(VO.class);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM-dd", JSON.defaultLocale);
dateFormat.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(dateFormat.parse("2012/04-01"), vo.getDate());
parser.close();
}
示例13: test_error_2
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error_2() throws Exception {
JSONException error = null;
try {
DefaultJSONParser parser = new DefaultJSONParser("{a 3}");
parser.config(Feature.AllowUnQuotedFieldNames, true);
parser.parseObject(A.class);
} catch (JSONException e) {
error = e;
}
Assert.assertNotNull(error);
}
示例14: test_getInput
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_getInput() {
String text = "{,,}";
char[] chars = text.toCharArray();
DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
JSONException error = null;
try {
parser.parseObject();
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例15: test_x
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_x() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}"));
VO vo = parser.parseObject(VO.class);
Assert.assertEquals(Type.XXXXXXXXXXXXXXXXXXXXXXXX, vo.getType());
parser.close();
}