本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.getLexer方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.getLexer方法的具体用法?Java DefaultJSONParser.getLexer怎么用?Java DefaultJSONParser.getLexer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.getLexer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseArray
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static final JSONArray parseArray(String text) {
if (text == null) {
return null;
}
JSONArray array;
DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 8) {
lexer.nextToken();
array = null;
} else if (lexer.token() == 20) {
array = null;
} else {
Collection array2 = new JSONArray();
parser.parseArray(array2);
parser.handleResovleTask(array2);
}
parser.close();
return array;
}
示例2: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
final JSONScanner lexer = (JSONScanner) parser.getLexer();
MediaContent object = new MediaContent();
lexer.matchField(mediaPrefix);
if (mediaDeserializer == null) {
//mediaDeserializer = parser.getMapping().getDeserializer(ObjectDeserializer.class);
}
mediaDeserializer.deserialze(parser, clazz, null);
lexer.matchField(imagePrefix);
imageDeserializer.deserialze(parser, clazz, null);
// if (lexer.token() != JSONToken.RBRACE)
// TODO Auto-generated method stub
return null;
}
示例3: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
Long longObject;
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 2) {
long longValue = lexer.longValue();
lexer.nextToken(16);
longObject = Long.valueOf(longValue);
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
longObject = TypeUtils.castToLong(value);
}
if (clazz == AtomicLong.class) {
return new AtomicLong(longObject.longValue());
}
return longObject;
}
示例4: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static <T> T deserialze(DefaultJSONParser parser) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 4) {
String val = lexer.stringVal();
lexer.nextToken(16);
return val.toCharArray();
} else if (lexer.token() == 2) {
Number val2 = lexer.integerValue();
lexer.nextToken(16);
return val2.toString().toCharArray();
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
return JSON.toJSONString(value).toCharArray();
}
}
示例5: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static <T> T deserialze(DefaultJSONParser parser) {
JSONLexer lexer = parser.getLexer();
long val;
if (lexer.token() == 2) {
val = lexer.longValue();
lexer.nextToken(16);
return new BigDecimal(val);
} else if (lexer.token() == 3) {
val = lexer.decimalValue();
lexer.nextToken(16);
return val;
} else {
Object value = parser.parse();
if (value == null) {
return null;
}
return TypeUtils.castToBigDecimal(value);
}
}
示例6: 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);
}
}
示例7: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 8) {
lexer.nextToken(16);
return null;
}
T intObj;
if (lexer.token() == 2) {
int val = lexer.intValue();
lexer.nextToken(16);
intObj = Integer.valueOf(val);
} else if (lexer.token() == 3) {
BigDecimal decimalValue = lexer.decimalValue();
lexer.nextToken(16);
intObj = Integer.valueOf(decimalValue.intValue());
} else {
intObj = TypeUtils.castToInt(parser.parse());
}
if (clazz == AtomicInteger.class) {
return new AtomicInteger(intObj.intValue());
}
return intObj;
}
示例8: parseArray
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public static void parseArray(Collection collection, ObjectDeserializer deser, DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 8) {
lexer.nextToken(16);
}
parser.accept(14, 14);
int index = 0;
while (true) {
collection.add(deser.deserialze(parser, type, Integer.valueOf(index)));
index++;
if (lexer.token() == 16) {
lexer.nextToken(14);
} else {
parser.accept(15, 16);
return;
}
}
}
示例9: 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();
Boolean boolObj;
if (lexer.token() == JSONToken.TRUE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.TRUE;
} else if (lexer.token() == JSONToken.FALSE) {
lexer.nextToken(JSONToken.COMMA);
boolObj = Boolean.FALSE;
} else if (lexer.token() == JSONToken.LITERAL_INT) {
int intValue = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
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 (T) new AtomicBoolean(boolObj.booleanValue());
}
return (T) boolObj;
}
示例10: 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();
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
return null;
}
Integer intObj;
if (lexer.token() == JSONToken.LITERAL_INT) {
int val = lexer.intValue();
lexer.nextToken(JSONToken.COMMA);
intObj = Integer.valueOf(val);
} else if (lexer.token() == JSONToken.LITERAL_FLOAT) {
BigDecimal decimalValue = lexer.decimalValue();
lexer.nextToken(JSONToken.COMMA);
intObj = Integer.valueOf(decimalValue.intValue());
} else {
Object value = parser.parse();
intObj = TypeUtils.castToInt(value);
}
if (clazz == AtomicInteger.class) {
return (T) new AtomicInteger(intObj.intValue());
}
return (T) intObj;
}
示例11: 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);
}
}
示例12: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 8) {
lexer.nextToken();
return null;
} else if (lexer.token() != 4) {
throw new JSONException("expect className");
} else {
String className = lexer.stringVal();
lexer.nextToken(16);
return TypeUtils.loadClass(className);
}
}
示例13: parseField
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 2) {
int val = lexer.intValue();
lexer.nextToken(16);
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), Integer.valueOf(val));
return;
} else {
setValue(object, val);
return;
}
}
Integer value;
if (lexer.token() == 8) {
value = null;
lexer.nextToken(16);
} else {
value = TypeUtils.castToInt(parser.parse());
}
if (value != null || getFieldClass() != Integer.TYPE) {
if (object == null) {
fieldValues.put(this.fieldInfo.getName(), value);
} else {
setValue(object, (Object) value);
}
}
}
示例14: deserialzeArrayMapping
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialzeArrayMapping(DefaultJSONParser parser, Type type, Object fieldName, Object object) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() != 14) {
throw new JSONException("error");
}
object = createInstance(parser, type);
int size = this.sortedFieldDeserializers.size();
int i = 0;
while (i < size) {
char seperator = i == size + -1 ? ']' : ',';
FieldDeserializer fieldDeser = (FieldDeserializer) this.sortedFieldDeserializers.get(i);
Class<?> fieldClass = fieldDeser.getFieldClass();
if (fieldClass == Integer.TYPE) {
fieldDeser.setValue(object, lexer.scanInt(seperator));
} else if (fieldClass == String.class) {
fieldDeser.setValue(object, lexer.scanString(seperator));
} else if (fieldClass == Long.TYPE) {
fieldDeser.setValue(object, lexer.scanLong(seperator));
} else if (fieldClass.isEnum()) {
fieldDeser.setValue(object, lexer.scanEnum(fieldClass, parser.getSymbolTable(), seperator));
} else {
lexer.nextToken(14);
fieldDeser.setValue(object, parser.parseObject(fieldDeser.getFieldType()));
if (seperator == ']') {
if (lexer.token() != 15) {
throw new JSONException("syntax error");
}
lexer.nextToken(16);
} else if (seperator == ',' && lexer.token() != 16) {
throw new JSONException("syntax error");
}
}
i++;
}
lexer.nextToken(16);
return object;
}
示例15: deserialze
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 4) {
String text = lexer.stringVal();
lexer.nextToken();
if (type == LocalDateTime.class) {
return LocalDateTime.parse(text);
}
if (type == LocalDate.class) {
return LocalDate.parse(text);
}
if (type == LocalTime.class) {
return LocalTime.parse(text);
}
if (type == ZonedDateTime.class) {
return ZonedDateTime.parse(text);
}
if (type == OffsetDateTime.class) {
return OffsetDateTime.parse(text);
}
if (type == OffsetTime.class) {
return OffsetTime.parse(text);
}
if (type == ZoneId.class) {
return ZoneId.of(text);
}
if (type == Period.class) {
return Period.parse(text);
}
if (type == Duration.class) {
return Duration.parse(text);
}
if (type == Instant.class) {
return Instant.parse(text);
}
return null;
}
throw new UnsupportedOperationException();
}