本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.parse方法的具体用法?Java DefaultJSONParser.parse怎么用?Java DefaultJSONParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@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;
}
示例2: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
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);
}
}
示例3: test_error11
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_error11() {
Exception error = null;
try {
DefaultJSONParser parser = new DefaultJSONParser("{]");
parser.parse();
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例4: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Object value = parser.parse();
if (value == null) {
return null;
}
String charset = (String) value;
return (T) Charset.forName(charset);
}
示例5: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Object value = parser.parse();
if (value == null) {
return null;
}
String path = (String) value;
return (T) new File(path);
}
示例6: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
String url = (String) parser.parse();
if (url == null) {
return null;
}
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new JSONException("create url error", e);
}
}
示例7: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Boolean boolObj;
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 6) {
lexer.nextToken(16);
boolObj = Boolean.TRUE;
} else if (lexer.token() == 7) {
lexer.nextToken(16);
boolObj = Boolean.FALSE;
} else if (lexer.token() == 2) {
int intValue = lexer.intValue();
lexer.nextToken(16);
if (intValue == 1) {
boolObj = Boolean.TRUE;
} else {
boolObj = Boolean.FALSE;
}
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
boolObj = TypeUtils.castToBoolean(value);
}
if (clazz == AtomicBoolean.class) {
return new AtomicBoolean(boolObj.booleanValue());
}
return boolObj;
}
示例8: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Object value = parser.parse();
return value == null //
? null //
: (T) TypeUtils.castToChar(value);
}
示例9: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
String value = parser.parse();
if (value == null) {
return null;
}
return new File(value);
}
示例10: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
try {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 2) {
Integer value = Integer.valueOf(lexer.intValue());
lexer.nextToken(16);
T t = this.ordinalMap.get(value);
if (t != null) {
return t;
}
throw new JSONException("parse enum " + this.enumClass.getName() + " error, value : " + value);
} else if (lexer.token() == 4) {
String strVal = lexer.stringVal();
lexer.nextToken(16);
if (strVal.length() == 0) {
return null;
}
Object value2 = this.nameMap.get(strVal);
return Enum.valueOf(this.enumClass, strVal);
} else if (lexer.token() == 8) {
lexer.nextToken(16);
return null;
} else {
throw new JSONException("parse enum " + this.enumClass.getName() + " error, value : " + parser.parse());
}
} catch (JSONException e) {
throw e;
} catch (Throwable e2) {
JSONException jSONException = new JSONException(e2.getMessage(), e2);
}
}
示例11: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
String text = (String) parser.parse();
if (text == null) {
return null;
}
String[] items = text.split("_");
if (items.length == 1) {
return new Locale(items[0]);
}
if (items.length == 2) {
return new Locale(items[0], items[1]);
}
return new Locale(items[0], items[1], items[2]);
}
示例12: test_double_in_object
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_double_in_object() {
DefaultJSONParser parser = new DefaultJSONParser("{\"double\":3.4}");
parser.config(Feature.UseBigDecimal, false);
Assert.assertEquals("{\"double\":3.4}", parser.getInput());
Object result = parser.parse();
Assert.assertEquals(3.4D, ((Map) result).get("double"));
}
示例13: test_true
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void test_true() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"@type\":\"java.util.LinkedHashMap\",\"name\":\"张三\"}"));
LinkedHashMap json = (LinkedHashMap) parser.parse();
Assert.assertEquals("张三", json.get("name"));
parser.close();
}
示例14: decode
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public final Object decode(String text) {
DefaultJSONParser parser = new DefaultJSONParser(text, config);
parser.config(Feature.DisableCircularReferenceDetect, true);
return parser.parse();
}
示例15: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Long val;
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 2) {
val = Long.valueOf(lexer.longValue());
lexer.nextToken(16);
} else if (lexer.token() == 4) {
String strVal = lexer.stringVal();
val = strVal;
lexer.nextToken(16);
if (lexer.isEnabled(Feature.AllowISO8601DateFormat)) {
JSONScanner iso8601Lexer = new JSONScanner(strVal);
if (iso8601Lexer.scanISO8601DateIfMatch()) {
val = iso8601Lexer.getCalendar().getTime();
}
iso8601Lexer.close();
}
} else if (lexer.token() == 8) {
lexer.nextToken();
val = null;
} else if (lexer.token() == 12) {
lexer.nextToken();
if (lexer.token() == 4) {
if (JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal())) {
lexer.nextToken();
parser.accept(17);
Class<?> type = TypeUtils.loadClass(lexer.stringVal());
if (type != null) {
clazz = type;
}
parser.accept(4);
parser.accept(16);
}
lexer.nextTokenWithColon(2);
if (lexer.token() == 2) {
long timeMillis = lexer.longValue();
lexer.nextToken();
val = Long.valueOf(timeMillis);
parser.accept(13);
} else {
throw new JSONException("syntax error : " + lexer.tokenName());
}
}
throw new JSONException("syntax error");
} else if (parser.getResolveStatus() == 2) {
parser.setResolveStatus(0);
parser.accept(16);
if (lexer.token() != 4) {
throw new JSONException("syntax error");
} else if ("val".equals(lexer.stringVal())) {
lexer.nextToken();
parser.accept(17);
val = parser.parse();
parser.accept(13);
} else {
throw new JSONException("syntax error");
}
} else {
val = parser.parse();
}
return cast(parser, clazz, fieldName, val);
}