本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.setContext方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.setContext方法的具体用法?Java DefaultJSONParser.setContext怎么用?Java DefaultJSONParser.setContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.setContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
JSONLexer lexer = parser.lexer;
final int token = lexer.token();
if (token == JSONToken.NULL
|| (token == JSONToken.LITERAL_STRING && lexer.stringVal().length() == 0)) {
setValue(object, null);
return;
}
ArrayList list = new ArrayList();
ParseContext context = parser.getContext();
parser.setContext(context, object, fieldInfo.name);
parseArray(parser, objectType, list);
parser.setContext(context);
if (object == null) {
fieldValues.put(fieldInfo.name, list);
} else {
setValue(object, list);
}
}
示例2: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
if (parser.getLexer().token() == 8) {
setValue(object, null);
return;
}
ArrayList list = new ArrayList();
ParseContext context = parser.getContext();
parser.setContext(context, object, this.fieldInfo.getName());
parseArray(parser, objectType, list);
parser.setContext(context);
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), list);
} else {
setValue(object, (Object) list);
}
}
示例3: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
final JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
return null;
}
Map<Object, Object> map = createMap(type);
ParseContext context = parser.getContext();
try {
parser.setContext(context, map, fieldName);
return (T) deserialze(parser, type, fieldName, map);
} finally {
parser.setContext(context);
}
}
示例4: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
if (parser.getLexer().token() == JSONToken.NULL) {
setValue(object, null);
return;
}
ArrayList list = new ArrayList();
ParseContext context = parser.getContext();
parser.setContext(context, object, fieldInfo.getName());
parseArray(parser, objectType, list);
parser.setContext(context);
if (object == null) {
fieldValues.put(fieldInfo.getName(), list);
} else {
setValue(object, list);
}
}
示例5: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
return null;
}
if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
throw new JSONException("syntax error");
}
lexer.nextToken();
T obj;
if (type == Point.class) {
obj = (T) parsePoint(parser, fieldName);
} else if (type == Rectangle.class) {
obj = (T) parseRectangle(parser);
} else if (type == Color.class) {
obj = (T) parseColor(parser);
} else if (type == Font.class) {
obj = (T) parseFont(parser);
} else {
throw new JSONException("not support awt class : " + type);
}
ParseContext context = parser.getContext();
parser.setContext(obj, fieldName);
parser.setContext(context);
return obj;
}
示例6: 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;
}
示例7: 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());
}