use of com.alibaba.fastjson.parser.JSONLexer in project fastjson by alibaba.
the class MediaDeserializer method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
final JSONLexer lexer = parser.getLexer();
if (lexer.token() != JSONToken.LBRACKET) {
throw new JSONException("error");
}
Media media = new Media();
int bitrate = lexer.scanInt(',');
int height = lexer.scanInt(',');
int width = lexer.scanInt(',');
String copyright = lexer.scanString(',');
long duration = lexer.scanLong(',');
String format = lexer.scanString(',');
List<String> persons = new ArrayList<String>();
lexer.scanStringArray(persons, ',');
String playerName = lexer.scanSymbolWithSeperator(parser.getSymbolTable(), ',');
long size = lexer.scanLong(',');
String title = lexer.scanString(',');
String uri = lexer.scanString(']');
lexer.nextToken(JSONToken.COMMA);
media.setBitrate(bitrate);
media.setHeight(height);
media.setWidth(width);
media.setCopyright(copyright);
media.setDuration(duration);
media.setFormat(format);
media.setPersons(persons);
media.setPlayer(playerName == null ? null : Player.valueOf(playerName));
media.setSize(size);
media.setTitle(title);
media.setUri(uri);
return (T) media;
}
use of com.alibaba.fastjson.parser.JSONLexer in project actframework by actframework.
the class FastJsonJodaDateCodec method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.LITERAL_STRING) {
String text = lexer.stringVal();
lexer.nextToken();
if (type == DateTime.class) {
DateTime dateTime = dateTimeCodec().parse(text);
return (T) dateTime;
} else if (type == LocalDateTime.class) {
LocalDateTime localDateTime = localDateTimeCodec().parse(text);
return (T) localDateTime;
} else if (type == LocalDate.class) {
LocalDate localDate = localDateCodec().parse(text);
return (T) localDate;
} else if (type == LocalTime.class) {
LocalTime localDate = LocalTime.parse(text);
return (T) localDate;
} else if (type == Period.class) {
Period period = Period.parse(text);
return (T) period;
} else if (type == Duration.class) {
Duration duration = Duration.parse(text);
return (T) duration;
} else if (type == Instant.class) {
Instant instant = Instant.parse(text);
return (T) instant;
}
} else {
throw new UnsupportedOperationException();
}
return null;
}
use of com.alibaba.fastjson.parser.JSONLexer in project actframework by actframework.
the class FastJsonSObjectCodec method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == JSONToken.LITERAL_STRING) {
String text = lexer.stringVal();
lexer.nextToken(JSONToken.COMMA);
return (T) resolver.resolve(text);
} else {
throw new UnsupportedOperationException();
}
}
Aggregations