本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.setResolveStatus方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.setResolveStatus方法的具体用法?Java DefaultJSONParser.setResolveStatus怎么用?Java DefaultJSONParser.setResolveStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.setResolveStatus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
if (this.fieldValueDeserilizer == null) {
this.fieldValueDeserilizer = parser.getConfig().getDeserializer(this.fieldInfo);
}
if (objectType instanceof ParameterizedType) {
parser.getContext().setType(objectType);
}
Object value = this.fieldValueDeserilizer.deserialze(parser, getFieldType(), this.fieldInfo.getName());
if (parser.getResolveStatus() == 1) {
ResolveTask task = parser.getLastResolveTask();
task.setFieldDeserializer(this);
task.setOwnerContext(parser.getContext());
parser.setResolveStatus(0);
} else if (object == null) {
fieldValues.put(this.fieldInfo.getName(), value);
} else {
setValue(object, value);
}
}
示例2: 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);
}
}
}
示例3: parseRef
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
private Object parseRef(DefaultJSONParser parser, Object fieldName) {
JSONLexer lexer = parser.getLexer();
lexer.nextTokenWithColon(JSONToken.LITERAL_STRING);
String ref = lexer.stringVal();
parser.setContext(parser.getContext(), fieldName);
parser.addResolveTask(new DefaultJSONParser.ResolveTask(parser.getContext(), ref));
parser.popContext();
parser.setResolveStatus(DefaultJSONParser.NeedToResolve);
lexer.nextToken(JSONToken.RBRACE);
parser.accept(JSONToken.RBRACE);
return null;
}
示例4: 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) {
getFieldValueDeserilizer(parser.getConfig());
}
Type fieldType = fieldInfo.fieldType;
if (objectType instanceof ParameterizedType) {
ParseContext objContext = parser.getContext();
objContext.type = objectType;
fieldType = FieldInfo.getFieldType(this.clazz, objectType, fieldType);
}
// ContextObjectDeserializer
Object value;
if (fieldValueDeserilizer instanceof JavaBeanDeserializer) {
JavaBeanDeserializer javaBeanDeser = (JavaBeanDeserializer) fieldValueDeserilizer;
value = javaBeanDeser.deserialze(parser, fieldType, fieldInfo.name, fieldInfo.parserFeatures);
} else {
if (this.fieldInfo.format != null && fieldValueDeserilizer instanceof ContextObjectDeserializer) {
value = ((ContextObjectDeserializer) fieldValueDeserilizer) //
.deserialze(parser, fieldType,
fieldInfo.name,
fieldInfo.format,
fieldInfo.parserFeatures);
} else {
value = fieldValueDeserilizer.deserialze(parser, fieldType, fieldInfo.name);
}
}
if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
DefaultJSONParser.ResolveTask task = parser.getLastResolveTask();
task.fieldDeserializer = this;
task.ownerContext = parser.getContext();
parser.setResolveStatus(DefaultJSONParser.NONE);
} else {
if (object == null) {
fieldValues.put(fieldInfo.name, value);
} else {
setValue(object, value);
}
}
}
示例5: parseMap
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static Object parseMap(DefaultJSONParser parser, Map<Object, Object> map, Type keyType, Type valueType, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 12 || lexer.token() == 16) {
ObjectDeserializer keyDeserializer = parser.getConfig().getDeserializer(keyType);
ObjectDeserializer valueDeserializer = parser.getConfig().getDeserializer(valueType);
lexer.nextToken(keyDeserializer.getFastMatchToken());
ParseContext context = parser.getContext();
while (lexer.token() != 13) {
try {
if (lexer.token() == 4 && lexer.isRef()) {
Map<Object, Object> object = null;
lexer.nextTokenWithColon(4);
if (lexer.token() == 4) {
String ref = lexer.stringVal();
if ("..".equals(ref)) {
object = context.getParentContext().getObject();
} else if ("$".equals(ref)) {
ParseContext rootContext = context;
while (rootContext.getParentContext() != null) {
rootContext = rootContext.getParentContext();
}
object = rootContext.getObject();
} else {
parser.addResolveTask(new ResolveTask(context, ref));
parser.setResolveStatus(1);
}
lexer.nextToken(13);
if (lexer.token() != 13) {
throw new JSONException("illegal ref");
}
lexer.nextToken(16);
parser.setContext(context);
return object;
}
throw new JSONException("illegal ref, " + JSONToken.name(lexer.token()));
}
if (map.size() == 0 && lexer.token() == 4 && JSON.DEFAULT_TYPE_KEY.equals(lexer.stringVal())) {
lexer.nextTokenWithColon(4);
lexer.nextToken(16);
if (lexer.token() == 13) {
lexer.nextToken();
return map;
}
lexer.nextToken(keyDeserializer.getFastMatchToken());
}
Object key = keyDeserializer.deserialze(parser, keyType, null);
if (lexer.token() != 17) {
throw new JSONException("syntax error, expect :, actual " + lexer.token());
}
lexer.nextToken(valueDeserializer.getFastMatchToken());
map.put(key, valueDeserializer.deserialze(parser, valueType, key));
if (lexer.token() == 16) {
lexer.nextToken(keyDeserializer.getFastMatchToken());
}
} finally {
parser.setContext(context);
}
}
lexer.nextToken(16);
parser.setContext(context);
return map;
}
throw new JSONException("syntax error, expect {, actual " + lexer.tokenName());
}
示例6: 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);
}