List of usage examples for com.google.gson.stream JsonToken END_ARRAY
JsonToken END_ARRAY
To view the source code for com.google.gson.stream JsonToken END_ARRAY.
Click Source Link
From source file:org.immutables.gson.stream.JsonParserReader.java
License:Apache License
private static JsonToken toGsonToken(com.fasterxml.jackson.core.JsonToken token) { switch (token) { case START_ARRAY: return JsonToken.BEGIN_ARRAY; case END_ARRAY: return JsonToken.END_ARRAY; case START_OBJECT: return JsonToken.BEGIN_OBJECT; case END_OBJECT: return JsonToken.END_OBJECT; case FIELD_NAME: return JsonToken.NAME; case VALUE_FALSE: return JsonToken.BOOLEAN; case VALUE_TRUE: return JsonToken.BOOLEAN; case VALUE_NULL: return JsonToken.NULL; case VALUE_NUMBER_INT: return JsonToken.NUMBER; case VALUE_NUMBER_FLOAT: return JsonToken.NUMBER; case VALUE_STRING: return JsonToken.STRING; default: // Not semantically equivalent return JsonToken.NULL; }//from w ww. java2s. co m }
From source file:org.immutables.mongo.bson4gson.BsonReader.java
License:Apache License
@Override public JsonToken peek() throws IOException { switch (state()) { case INITIAL: case SCOPE_DOCUMENT: case TYPE://from ww w. j a v a2 s .c o m advance(); return toGsonToken(delegate.getCurrentBsonType()); case NAME: return JsonToken.NAME; case END_OF_DOCUMENT: return JsonToken.END_OBJECT; case END_OF_ARRAY: return JsonToken.END_ARRAY; case DONE: return JsonToken.END_DOCUMENT; case VALUE: return toGsonToken(delegate.getCurrentBsonType()); default: throw new IllegalStateException( "Unexpected state: " + state() + " currentType:" + delegate.getCurrentBsonType()); } }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void parseMaintainers(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException { reader.beginArray();//from w ww . jav a 2s.co m String name = null, email = null; JsonToken token = reader.peek(); while (token != JsonToken.END_ARRAY) { switch (token) { case BEGIN_OBJECT: reader.beginObject(); name = email = null; break; case END_OBJECT: reader.endObject(); plugin.addMaintainer(email, name); break; case NAME: String tagName = reader.nextName(); if ("name".equals(tagName)) { name = reader.nextString(); break; } if ("email".equals(tagName)) { email = reader.nextString(); break; } default: Assert.isTrue(false, "Unexpected token"); break; } token = reader.peek(); } reader.endArray(); }
From source file:org.jetbrains.io.JsonReaderEx.java
License:Apache License
/** * Returns the type of the next token without consuming it. *///www .j a v a 2 s . com 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.opendaylight.restconf.jersey.providers.JsonToPATCHBodyReader.java
License:Open Source License
/** * Parse data defined in value node and saves it to buffer * @param value Buffer to read value node * @param in JsonReader reader/*from ww w.j ava 2s. c o m*/ * @throws IOException */ private void readValueNode(@Nonnull final StringBuffer value, @Nonnull final JsonReader in) throws IOException { in.beginObject(); value.append("{"); value.append("\"" + in.nextName() + "\"" + ":"); 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); } in.endObject(); value.append("}"); }
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 www .j av a 2 s . c o m * @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.ttrssreader.net.JSONConnector.java
License:Open Source License
private Set<Label> parseLabels(final JsonReader reader) throws IOException { Set<Label> ret = new HashSet<>(); if (reader.peek().equals(JsonToken.BEGIN_ARRAY)) { reader.beginArray();//ww w. j a va2 s . co m } else { reader.skipValue(); return ret; } try { while (reader.hasNext()) { Label label = new Label(); reader.beginArray(); try { label.id = Integer.parseInt(reader.nextString()); label.caption = reader.nextString(); label.foregroundColor = reader.nextString(); label.backgroundColor = reader.nextString(); label.checked = true; } catch (IllegalArgumentException e) { e.printStackTrace(); reader.skipValue(); continue; } ret.add(label); reader.endArray(); } reader.endArray(); } catch (Exception e) { // Ignore exceptions here try { if (reader.peek().equals(JsonToken.END_ARRAY)) reader.endArray(); } catch (Exception ee) { // Empty! } } return ret; }
From source file:org.wso2.carbon.governance.rest.api.internal.JSONMessageBodyReader.java
License:Open Source License
/** * Traverse through a json array and maps the array elements to a {@link Map} * * @param reader {@link JsonReader} * @return map with json array values mapped to key value pairs. * @throws IOException If unable to parse the json array. *//*from w ww . j a va2s .c o m*/ private Map<String, Object> handleArray(JsonReader reader) throws IOException { Map<String, Object> values = new HashMap<>(); reader.beginArray(); JsonToken token = reader.peek(); while (token != null) { if (token.equals(JsonToken.END_ARRAY)) { reader.endArray(); return values; } else { handleObject(reader, values, token, true); } token = reader.peek(); } return values; }
From source file:ru.orangesoftware.financisto2.export.flowzr.FlowzrSyncEngine.java
License:Open Source License
public <T> int readMessage(JsonReader reader, String tableName, Class<T> clazz, long last_sync_ts) throws IOException, JSONException, Exception { String n = null;/*from w ww . java 2 s .c om*/ int i = 0; while (reader.hasNext()) { JsonToken peek = reader.peek(); String v = null; if (peek == JsonToken.BEGIN_OBJECT) { reader.beginObject(); } else if (peek == JsonToken.NAME) { n = reader.nextName(); } else if (peek == JsonToken.BEGIN_ARRAY) { if (n.equals(tableName)) { i = readJsnArr(reader, tableName, clazz); } else { if (n.equals("params")) { reader.beginArray(); if (reader.hasNext()) { reader.beginObject(); if (reader.hasNext()) { n = reader.nextName(); v = reader.nextString(); } reader.endObject(); } reader.endArray(); } else { reader.skipValue(); } } } else if (peek == JsonToken.END_OBJECT) { reader.endObject(); } else if (peek == JsonToken.END_ARRAY) { reader.endArray(); } } return i; }
From source file:se.sics.datamodel.gson.TypeInfoAdapter.java
License:Open Source License
@Override public TypeInfo read(JsonReader reader) throws IOException { String typeName;/*from w w w . j ava 2s . c om*/ Gson gson = GsonHelper.getGson(); reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("typeName")) { throw new IOException(); } typeName = reader.nextString(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("fieldMap")) { throw new IOException(); } if (reader.peek() != JsonToken.BEGIN_ARRAY) { throw new IOException(); } reader.beginArray(); TypeInfo.Builder tiBuilder = new TypeInfo.Builder(typeName); while (reader.peek() != JsonToken.END_ARRAY) { if (reader.peek() != JsonToken.BEGIN_OBJECT) { throw new IOException(); } reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("id")) { throw new IOException(); } ByteId fieldId = new ByteId((byte[]) gson.fromJson(reader, byte[].class)); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("field")) { throw new IOException(); } FieldInfo fieldInfo = gson.fromJson(reader, FieldInfo.class); tiBuilder.put(fieldId, fieldInfo); reader.endObject(); } reader.endArray(); reader.endObject(); return tiBuilder.build(); }