Java Code Examples for com.alibaba.fastjson.parser.JSONToken#LITERAL_STRING
The following examples show how to use
com.alibaba.fastjson.parser.JSONToken#LITERAL_STRING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSerializer.java From joyrpc with Apache License 2.0 | 6 votes |
/** * 读取字符串 * * @param lexer 文法 * @param field 字段 * @param nullable 是否可以null */ protected String parseString(final JSONLexer lexer, final String field, final boolean nullable) { String result = null; switch (lexer.token()) { case JSONToken.LITERAL_STRING: result = lexer.stringVal(); lexer.nextToken(); break; case JSONToken.NULL: if (!nullable) { throw new SerializerException("syntax error: invalid " + field); } lexer.nextToken(); break; default: throw new SerializerException("syntax error: invalid " + field); } return result; }
Example 2
Source File: ArrayListTypeFieldDeserializer.java From uavstack with Apache License 2.0 | 6 votes |
@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); } }
Example 3
Source File: FastJsonKeywordCodec.java From actframework with Apache License 2.0 | 5 votes |
@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) Keyword.of(text); } else { throw new UnsupportedOperationException(); } }
Example 4
Source File: FastJsonSObjectCodec.java From actframework with Apache License 2.0 | 5 votes |
@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(); } }
Example 5
Source File: AwtCodec.java From uavstack with Apache License 2.0 | 4 votes |
protected Font parseFont(DefaultJSONParser parser) { JSONLexer lexer = parser.lexer; int size = 0, style = 0; String name = null; for (;;) { if (lexer.token() == JSONToken.RBRACE) { lexer.nextToken(); break; } String key; if (lexer.token() == JSONToken.LITERAL_STRING) { key = lexer.stringVal(); lexer.nextTokenWithColon(JSONToken.LITERAL_INT); } else { throw new JSONException("syntax error"); } if (key.equalsIgnoreCase("name")) { if (lexer.token() == JSONToken.LITERAL_STRING) { name = lexer.stringVal(); lexer.nextToken(); } else { throw new JSONException("syntax error"); } } else if (key.equalsIgnoreCase("style")) { if (lexer.token() == JSONToken.LITERAL_INT) { style = lexer.intValue(); lexer.nextToken(); } else { throw new JSONException("syntax error"); } } else if (key.equalsIgnoreCase("size")) { if (lexer.token() == JSONToken.LITERAL_INT) { size = lexer.intValue(); lexer.nextToken(); } else { throw new JSONException("syntax error"); } } else { throw new JSONException("syntax error, " + key); } if (lexer.token() == JSONToken.COMMA) { lexer.nextToken(JSONToken.LITERAL_STRING); } } return new Font(name, style, size); }
Example 6
Source File: FastJsonSObjectCodec.java From actframework with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 7
Source File: JSONPath_t.java From coming with MIT License | 4 votes |
public void extract(JSONPath path, DefaultJSONParser parser, Context context) { JSONLexerBase lexer = (JSONLexerBase) parser.lexer; JSONArray array; if (context.object == null) { context.object = array = new JSONArray(); } else { array = (JSONArray) context.object; } for (int i = array.size(); i < propertyNamesHash.length; ++i) { array.add(null); } // if (lexer.token() == JSONToken.LBRACKET) { // lexer.nextToken(); // JSONArray array; // // array = new JSONArray(); // for (;;) { // if (lexer.token() == JSONToken.LBRACE) { // int index = lexer.seekObjectToField(propertyNamesHash); // int matchStat = lexer.matchStat; // if (matchStat == JSONLexer.VALUE) { // Object value; // switch (lexer.token()) { // case JSONToken.LITERAL_INT: // value = lexer.integerValue(); // lexer.nextToken(); // break; // case JSONToken.LITERAL_STRING: // value = lexer.stringVal(); // lexer.nextToken(); // break; // default: // value = parser.parse(); // break; // } // // array.add(index, value); // if (lexer.token() == JSONToken.RBRACE) { // lexer.nextToken(); // continue; // } else { // lexer.skipObject(); // } // } else { // lexer.skipObject(); // } // } // // if (lexer.token() == JSONToken.RBRACKET) { // break; // } else if (lexer.token() == JSONToken.COMMA) { // lexer.nextToken(); // continue; // } else { // throw new JSONException("illegal json."); // } // } // // context.object = array; // return; // } for_: for (;;) { int index = lexer.seekObjectToField(propertyNamesHash); int matchStat = lexer.matchStat; if (matchStat == JSONLexer.VALUE) { Object value; switch (lexer.token()) { case JSONToken.LITERAL_INT: value = lexer.integerValue(); lexer.nextToken(JSONToken.COMMA); break; case JSONToken.LITERAL_FLOAT: value = lexer.decimalValue(); lexer.nextToken(JSONToken.COMMA); break; case JSONToken.LITERAL_STRING: value = lexer.stringVal(); lexer.nextToken(JSONToken.COMMA); break; default: value = parser.parse(); break; } array.set(index, value); if (lexer.token() == JSONToken.COMMA) { continue for_; } } break; } }
Example 8
Source File: JSONPath_s.java From coming with MIT License | 4 votes |
public void extract(JSONPath path, DefaultJSONParser parser, Context context) { JSONLexerBase lexer = (JSONLexerBase) parser.lexer; JSONArray array; if (context.object == null) { context.object = array = new JSONArray(); } else { array = (JSONArray) context.object; } for (int i = array.size(); i < propertyNamesHash.length; ++i) { array.add(null); } // if (lexer.token() == JSONToken.LBRACKET) { // lexer.nextToken(); // JSONArray array; // // array = new JSONArray(); // for (;;) { // if (lexer.token() == JSONToken.LBRACE) { // int index = lexer.seekObjectToField(propertyNamesHash); // int matchStat = lexer.matchStat; // if (matchStat == JSONLexer.VALUE) { // Object value; // switch (lexer.token()) { // case JSONToken.LITERAL_INT: // value = lexer.integerValue(); // lexer.nextToken(); // break; // case JSONToken.LITERAL_STRING: // value = lexer.stringVal(); // lexer.nextToken(); // break; // default: // value = parser.parse(); // break; // } // // array.add(index, value); // if (lexer.token() == JSONToken.RBRACE) { // lexer.nextToken(); // continue; // } else { // lexer.skipObject(); // } // } else { // lexer.skipObject(); // } // } // // if (lexer.token() == JSONToken.RBRACKET) { // break; // } else if (lexer.token() == JSONToken.COMMA) { // lexer.nextToken(); // continue; // } else { // throw new JSONException("illegal json."); // } // } // // context.object = array; // return; // } for_: for (;;) { int index = lexer.seekObjectToField(propertyNamesHash); int matchStat = lexer.matchStat; if (matchStat == JSONLexer.VALUE) { Object value; switch (lexer.token()) { case JSONToken.LITERAL_INT: value = lexer.integerValue(); lexer.nextToken(JSONToken.COMMA); break; case JSONToken.LITERAL_FLOAT: value = lexer.decimalValue(); lexer.nextToken(JSONToken.COMMA); break; case JSONToken.LITERAL_STRING: value = lexer.stringVal(); lexer.nextToken(JSONToken.COMMA); break; default: value = parser.parse(); break; } array.set(index, value); if (lexer.token() == JSONToken.COMMA) { continue for_; } } break; } }
Example 9
Source File: EnumDict.java From hsweb-framework with Apache License 2.0 | 4 votes |
@Override public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 10
Source File: CharacterCodec.java From uavstack with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 11
Source File: FastJsonJodaDateCodec.java From actframework with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 12
Source File: AwtCodec.java From uavstack with Apache License 2.0 | 4 votes |
protected Color parseColor(DefaultJSONParser parser) { JSONLexer lexer = parser.lexer; int r = 0, g = 0, b = 0, alpha = 0; for (;;) { if (lexer.token() == JSONToken.RBRACE) { lexer.nextToken(); break; } String key; if (lexer.token() == JSONToken.LITERAL_STRING) { key = lexer.stringVal(); lexer.nextTokenWithColon(JSONToken.LITERAL_INT); } else { throw new JSONException("syntax error"); } int val; if (lexer.token() == JSONToken.LITERAL_INT) { val = lexer.intValue(); lexer.nextToken(); } else { throw new JSONException("syntax error"); } if (key.equalsIgnoreCase("r")) { r = val; } else if (key.equalsIgnoreCase("g")) { g = val; } else if (key.equalsIgnoreCase("b")) { b = val; } else if (key.equalsIgnoreCase("alpha")) { alpha = val; } else { throw new JSONException("syntax error, " + key); } if (lexer.token() == JSONToken.COMMA) { lexer.nextToken(JSONToken.LITERAL_STRING); } } return new Color(r, g, b, alpha); }
Example 13
Source File: YearMonthSerialization.java From joyrpc with Apache License 2.0 | 4 votes |
@Override public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 14
Source File: FastJsonKeywordCodec.java From actframework with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 15
Source File: CharArrayCodec.java From uavstack with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 16
Source File: JodaCodec.java From uavstack with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 17
Source File: Jdk8DateCodec.java From uavstack with Apache License 2.0 | 4 votes |
public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 18
Source File: TimeDeserializer.java From uavstack with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { JSONLexer lexer = parser.lexer; if (lexer.token() == JSONToken.COMMA) { lexer.nextToken(JSONToken.LITERAL_STRING); if (lexer.token() != JSONToken.LITERAL_STRING) { throw new JSONException("syntax error"); } lexer.nextTokenWithColon(JSONToken.LITERAL_INT); if (lexer.token() != JSONToken.LITERAL_INT) { throw new JSONException("syntax error"); } long time = lexer.longValue(); lexer.nextToken(JSONToken.RBRACE); if (lexer.token() != JSONToken.RBRACE) { throw new JSONException("syntax error"); } lexer.nextToken(JSONToken.COMMA); return (T) new java.sql.Time(time); } Object val = parser.parse(); if (val == null) { return null; } if (val instanceof java.sql.Time) { return (T) val; } else if (val instanceof BigDecimal) { return (T) new java.sql.Time(TypeUtils.longValue((BigDecimal) val)); } else if (val instanceof Number) { return (T) new java.sql.Time(((Number) val).longValue()); } else if (val instanceof String) { String strVal = (String) val; if (strVal.length() == 0) { return null; } long longVal; JSONScanner dateLexer = new JSONScanner(strVal); if (dateLexer.scanISO8601DateIfMatch()) { longVal = dateLexer.getCalendar().getTimeInMillis(); } else { boolean isDigit = true; for (int i = 0; i< strVal.length(); ++i) { char ch = strVal.charAt(i); if (ch < '0' || ch > '9') { isDigit = false; break; } } if (!isDigit) { dateLexer.close(); return (T) java.sql.Time.valueOf(strVal); } longVal = Long.parseLong(strVal); } dateLexer.close(); return (T) new java.sql.Time(longVal); } throw new JSONException("parse error"); }
Example 19
Source File: MonthDaySerialization.java From joyrpc with Apache License 2.0 | 4 votes |
@Override public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }
Example 20
Source File: ZoneIdSerialization.java From joyrpc with Apache License 2.0 | 4 votes |
@Override public int getFastMatchToken() { return JSONToken.LITERAL_STRING; }