use of com.alibaba.fastjson.parser.JSONLexer in project fastjson by alibaba.
the class CalendarCodec method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
Object value = DateCodec.instance.deserialze(parser, type, fieldName);
if (value instanceof Calendar) {
return (T) value;
}
Date date = (Date) value;
if (date == null) {
return null;
}
JSONLexer lexer = parser.lexer;
Calendar calendar = Calendar.getInstance(lexer.getTimeZone(), lexer.getLocale());
calendar.setTime(date);
if (type == XMLGregorianCalendar.class) {
return (T) createXMLGregorianCalendar((GregorianCalendar) calendar);
}
return (T) calendar;
}
use of com.alibaba.fastjson.parser.JSONLexer in project uavstack by uavorg.
the class ASMJavaBeanDeserializer method parseField.
public boolean parseField(DefaultJSONParser parser, String key, Object object, Type objectType, Map<String, Object> fieldValues) {
// xxx
JSONLexer lexer = parser.getLexer();
Map<String, FieldDeserializer> feildDeserializerMap = serializer.getFieldDeserializerMap();
FieldDeserializer fieldDeserializer = feildDeserializerMap.get(key);
if (fieldDeserializer == null) {
for (Map.Entry<String, FieldDeserializer> entry : feildDeserializerMap.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
fieldDeserializer = entry.getValue();
break;
}
}
}
if (fieldDeserializer == null) {
this.serializer.parseExtra(parser, object, key);
return false;
}
lexer.nextTokenWithColon(fieldDeserializer.getFastMatchToken());
fieldDeserializer.parseField(parser, object, objectType, fieldValues);
return true;
}
use of com.alibaba.fastjson.parser.JSONLexer in project uavstack by uavorg.
the class AbstractDateDeserializer method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
JSONLexer lexer = parser.getLexer();
Object val;
if (lexer.token() == JSONToken.LITERAL_INT) {
val = lexer.longValue();
lexer.nextToken(JSONToken.COMMA);
} else if (lexer.token() == JSONToken.LITERAL_STRING) {
String strVal = lexer.stringVal();
val = strVal;
lexer.nextToken(JSONToken.COMMA);
if (lexer.isEnabled(Feature.AllowISO8601DateFormat)) {
JSONScanner iso8601Lexer = new JSONScanner(strVal);
if (iso8601Lexer.scanISO8601DateIfMatch()) {
val = iso8601Lexer.getCalendar().getTime();
}
iso8601Lexer.close();
}
} else if (lexer.token() == JSONToken.NULL) {
lexer.nextToken();
val = null;
} else if (lexer.token() == JSONToken.LBRACE) {
lexer.nextToken();
String key;
if (lexer.token() == JSONToken.LITERAL_STRING) {
key = lexer.stringVal();
if (JSON.DEFAULT_TYPE_KEY.equals(key)) {
lexer.nextToken();
parser.accept(JSONToken.COLON);
String typeName = lexer.stringVal();
Class<?> type = TypeUtils.loadClass(typeName);
if (type != null) {
clazz = type;
}
parser.accept(JSONToken.LITERAL_STRING);
parser.accept(JSONToken.COMMA);
}
lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
} else {
throw new JSONException("syntax error");
}
long timeMillis;
if (lexer.token() == JSONToken.LITERAL_INT) {
timeMillis = lexer.longValue();
lexer.nextToken();
} else {
throw new JSONException("syntax error : " + lexer.tokenName());
}
val = timeMillis;
parser.accept(JSONToken.RBRACE);
} else if (parser.getResolveStatus() == DefaultJSONParser.TypeNameRedirect) {
parser.setResolveStatus(DefaultJSONParser.NONE);
parser.accept(JSONToken.COMMA);
if (lexer.token() == JSONToken.LITERAL_STRING) {
if (!"val".equals(lexer.stringVal())) {
throw new JSONException("syntax error");
}
lexer.nextToken();
} else {
throw new JSONException("syntax error");
}
parser.accept(JSONToken.COLON);
val = parser.parse();
parser.accept(JSONToken.RBRACE);
} else {
val = parser.parse();
}
return (T) cast(parser, clazz, fieldName, val);
}
use of com.alibaba.fastjson.parser.JSONLexer in project uavstack by uavorg.
the class CharArrayDeserializer method deserialze.
@SuppressWarnings("unchecked")
public static <T> T deserialze(DefaultJSONParser parser) {
final JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.LITERAL_STRING) {
String val = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toCharArray();
}
if (lexer.token() == JSONToken.LITERAL_INT) {
Number val = lexer.integerValue();
lexer.nextToken(JSONToken.COMMA);
return (T) val.toString().toCharArray();
}
Object value = parser.parse();
if (value == null) {
return null;
}
return (T) JSON.toJSONString(value).toCharArray();
}
use of com.alibaba.fastjson.parser.JSONLexer in project uavstack by uavorg.
the class JavaBeanDeserializer method parseExtra.
void parseExtra(DefaultJSONParser parser, Object object, String key) {
// xxx
final JSONLexer lexer = parser.getLexer();
if (!lexer.isEnabled(Feature.IgnoreNotMatch)) {
throw new JSONException("setter not found, class " + clazz.getName() + ", property " + key);
}
lexer.nextTokenWithColon();
Type type = FilterUtils.getExtratype(parser, object, key);
Object value;
if (type == null) {
// skip
value = parser.parse();
} else {
value = parser.parseObject(type);
}
FilterUtils.processExtra(parser, object, key, value);
}
Aggregations