List of usage examples for com.google.gson.stream JsonToken STRING
JsonToken STRING
To view the source code for com.google.gson.stream JsonToken STRING.
Click Source Link
From source file:org.immutables.mongo.bson4gson.BsonReader.java
License:Apache License
private static JsonToken toGsonToken(BsonType type) { switch (type) { case END_OF_DOCUMENT: return JsonToken.END_DOCUMENT; case DOCUMENT: return JsonToken.BEGIN_OBJECT; case ARRAY://from w ww. j a v a2s .com return JsonToken.BEGIN_ARRAY; case BOOLEAN: return JsonToken.BOOLEAN; case STRING: case SYMBOL: case OBJECT_ID: case BINARY: case REGULAR_EXPRESSION: return JsonToken.STRING; case DATE_TIME: case DOUBLE: case INT32: case INT64: case TIMESTAMP: case DECIMAL128: return JsonToken.NUMBER; case NULL: return JsonToken.NULL; default: // not really sure what to do with this type return JsonToken.NULL; } }
From source file:org.jetbrains.io.JsonReaderEx.java
License:Apache License
/** * Returns the type of the next token without consuming it. *//*ww w . j av a 2 s . c om*/ public JsonToken peek() { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } switch (p) { case PEEKED_BEGIN_OBJECT: return JsonToken.BEGIN_OBJECT; case PEEKED_END_OBJECT: return JsonToken.END_OBJECT; case PEEKED_BEGIN_ARRAY: return JsonToken.BEGIN_ARRAY; case PEEKED_END_ARRAY: return JsonToken.END_ARRAY; case PEEKED_SINGLE_QUOTED_NAME: case PEEKED_DOUBLE_QUOTED_NAME: case PEEKED_UNQUOTED_NAME: return JsonToken.NAME; case PEEKED_TRUE: case PEEKED_FALSE: return JsonToken.BOOLEAN; case PEEKED_NULL: return JsonToken.NULL; case PEEKED_SINGLE_QUOTED: case PEEKED_DOUBLE_QUOTED: case PEEKED_UNQUOTED: case PEEKED_BUFFERED: return JsonToken.STRING; case PEEKED_LONG: case PEEKED_NUMBER: return JsonToken.NUMBER; case PEEKED_EOF: return JsonToken.END_DOCUMENT; default: throw new AssertionError(); } }
From source file:org.jetbrains.io.JsonReaderEx.java
License:Apache License
public String nextAsString() { return peek() == JsonToken.STRING ? nextString() : null; }
From source file:org.opendaylight.restconf.jersey.providers.JsonToPATCHBodyReader.java
License:Open Source License
/** * Parse one value object of data and saves it to buffer * @param value Buffer to read value object * @param in JsonReader reader//from ww w . jav a2 s .c om * @throws IOException */ private void readValueObject(@Nonnull final StringBuffer value, @Nonnull final JsonReader in) throws IOException { in.beginObject(); value.append("{"); while (in.hasNext()) { value.append("\"" + in.nextName() + "\""); value.append(":"); if (in.peek() == JsonToken.STRING) { value.append("\"" + in.nextString() + "\""); } else { if (in.peek() == JsonToken.BEGIN_ARRAY) { in.beginArray(); value.append("["); while (in.hasNext()) { readValueObject(value, in); if (in.peek() != JsonToken.END_ARRAY) { value.append(","); } } in.endArray(); value.append("]"); } else { readValueObject(value, in); } } if (in.peek() != JsonToken.END_OBJECT) { value.append(","); } } in.endObject(); value.append("}"); }
From source file:org.wso2.carbon.governance.rest.api.internal.JSONMessageBodyReader.java
License:Open Source License
/** * Traverses through a json object and maps the keys and values to a {@link Map} * * @param reader {@link JsonReader} * @param map map that the values to be added. * @param token {@link JsonToken} * @param isArray whether the object is inside a json array * @throws IOException If unable to parse the json object *//*w ww . j a v a2 s . c o m*/ protected void handleObject(JsonReader reader, Map<String, Object> map, JsonToken token, boolean isArray) throws IOException { String key = null; while (true) { if (token == null) { token = reader.peek(); } if (JsonToken.BEGIN_OBJECT.equals(token)) { reader.beginObject(); } else if (JsonToken.END_OBJECT.equals(token)) { reader.endObject(); } else if (JsonToken.NAME.equals(token)) { key = reader.nextName(); } else if (JsonToken.STRING.equals(token)) { String value = reader.nextString(); handleValue(key, value, map, isArray); key = null; } else if (JsonToken.NUMBER.equals(token)) { Double value = reader.nextDouble(); handleValue(key, value, map, isArray); key = null; } else if (token.equals(JsonToken.BEGIN_ARRAY)) { Map<String, Object> values = handleArray(reader); if (key != null) { map.put(key, values); } } else { reader.skipValue(); } if (reader.hasNext()) { token = reader.peek(); } else { break; } } }
From source file:ru.orangesoftware.financisto2.export.flowzr.FlowzrSyncEngine.java
License:Open Source License
public <T> int readJsnArr(JsonReader reader, String tableName, Class<T> clazz) throws IOException, JSONException, Exception { JSONObject o = new JSONObject(); JsonToken peek = reader.peek();// w ww. j a va2 s . c om String n = null; reader.beginArray(); int j = 0; int i = 0; while (reader.hasNext()) { peek = reader.peek(); if (reader.peek() == JsonToken.BEGIN_OBJECT) { reader.beginObject(); } else if (reader.peek() == JsonToken.END_OBJECT) { reader.endObject(); } o = new JSONObject(); while (reader.hasNext()) { peek = reader.peek(); if (peek == JsonToken.NAME) { n = reader.nextName(); } else if (peek == JsonToken.BEGIN_OBJECT) { reader.beginObject(); } else if (peek == JsonToken.END_OBJECT) { reader.endObject(); } else if (peek == JsonToken.BOOLEAN) { try { o.put(n, reader.nextBoolean()); } catch (JSONException e) { e.printStackTrace(); } } else if (peek == JsonToken.STRING) { try { o.put(n, reader.nextString()); } catch (JSONException e) { e.printStackTrace(); } } else if (peek == JsonToken.NUMBER) { try { o.put(n, reader.nextDouble()); } catch (JSONException e) { e.printStackTrace(); } } } reader.endObject(); if (o.has("key")) { i = i + 1; j = j + 1; if (j % 100 == 0) { j = 2; } saveEntityFromJson(o, tableName, clazz, i); if (i % 10 == 0) { flowzrSyncActivity.notifyUser( flowzrSyncActivity.getString(R.string.flowzr_sync_receiving) + " " + tableName + ". " + flowzrSyncActivity.getString(R.string.hint_run_background), (int) (Math.round(j))); } } } reader.endArray(); return i; }