Search in sources :

Example 86 with JSONLexer

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;
}
Also used : Media(data.media.Media) ArrayList(java.util.ArrayList) JSONException(com.alibaba.fastjson.JSONException) JSONLexer(com.alibaba.fastjson.parser.JSONLexer)

Example 87 with JSONLexer

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;
}
Also used : JSONLexer(com.alibaba.fastjson.parser.JSONLexer)

Example 88 with JSONLexer

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();
    }
}
Also used : JSONLexer(com.alibaba.fastjson.parser.JSONLexer)

Aggregations

JSONLexer (com.alibaba.fastjson.parser.JSONLexer)88 JSONException (com.alibaba.fastjson.JSONException)42 BigDecimal (java.math.BigDecimal)11 JSONObject (com.alibaba.fastjson.JSONObject)10 Point (java.awt.Point)9 ParameterizedType (java.lang.reflect.ParameterizedType)7 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)6 ParseContext (com.alibaba.fastjson.parser.ParseContext)6 IOException (java.io.IOException)6 Type (java.lang.reflect.Type)6 Font (java.awt.Font)5 Rectangle (java.awt.Rectangle)5 TypeVariable (java.lang.reflect.TypeVariable)5 ArrayList (java.util.ArrayList)5 JSONScanner (com.alibaba.fastjson.parser.JSONScanner)4 Date (java.util.Date)4 Map (java.util.Map)4 JSONArray (com.alibaba.fastjson.JSONArray)3 FieldInfo (com.alibaba.fastjson.util.FieldInfo)3 Color (java.awt.Color)3