List of usage examples for com.google.gson.stream JsonToken NAME
JsonToken NAME
To view the source code for com.google.gson.stream JsonToken NAME.
Click Source Link
From source file:dtool.dub.DubDescribeParser.java
License:Open Source License
@Override protected void readData(JsonReaderExt jsonParser) throws IOException, DubBundleException { jsonParser.consumeExpected(JsonToken.BEGIN_OBJECT); while (jsonParser.hasNext()) { JsonToken tokenType = jsonParser.peek(); if (tokenType == JsonToken.NAME) { String propertyName = jsonParser.nextName(); if (propertyName.equals("mainPackage")) { bundleName = jsonParser.consumeStringValue(); } else if (propertyName.equals("packages")) { bundles = readDescribedBundles(jsonParser); } else { jsonParser.skipValue();//w w w.ja v a 2s.c om } } else { jsonParser.errorUnexpected(tokenType); } } jsonParser.consumeExpected(JsonToken.END_OBJECT); }
From source file:dtool.dub.DubManifestParser.java
License:Open Source License
protected DubManifestParser readBundle(JsonReaderExt jsonReader) throws IOException, DubBundleException { jsonReader.consumeExpected(JsonToken.BEGIN_OBJECT); while (jsonReader.hasNext()) { JsonToken tokenType = jsonReader.peek(); if (tokenType == JsonToken.NAME) { String propertyName = jsonReader.nextName(); if (propertyName.equals("name")) { bundleName = jsonReader.consumeStringValue(); } else if (propertyName.equals("version")) { version = jsonReader.consumeStringValue(); } else if (propertyName.equals("path")) { pathString = jsonReader.consumeStringValue(); } else if (propertyName.equals("importPaths")) { sourceFolders = parseSourcePaths(jsonReader); } else if (propertyName.equals("dependencies")) { dependencies = parseDependencies(jsonReader); } else if (propertyName.equals("files")) { bundleFiles = parseFiles(jsonReader); } else if (propertyName.equals("targetName")) { targetName = jsonReader.consumeStringValue(); } else if (propertyName.equals("targetPath")) { targetPath = jsonReader.consumeStringValue(); } else if (propertyName.equals("configurations")) { configurations = parseConfigurations(jsonReader); } else { jsonReader.skipValue();/*from ww w.j a v a 2s. c om*/ } } else { jsonReader.errorUnexpected(tokenType); } } jsonReader.consumeExpected(JsonToken.END_OBJECT); return this; }
From source file:json.tests.reader.JSONStreamReader.java
License:Open Source License
/** * {@inheritDoc}//w w w.ja v a2s . c om */ @Override public String nextName() throws IOException { if (this.currentToken == JsonToken.NAME) { String tempElementName = this.currentElementName; goToNextToken(false, false); return tempElementName; } else { throw new IllegalStateException("Expected a NAME token but found " + this.currentToken); } }
From source file:json.tests.reader.JSONStreamReader.java
License:Open Source License
/** * Remove a primitive value from the current element stack. *///w w w . ja va 2 s. c o m private void popPrimitive() { // no need to empty-check if (this.lastToken == JsonToken.NAME) { this.elementsStack.pop(); } }
From source file:net.oneandone.stool.configuration.adapter.ExtensionsAdapter.java
License:Apache License
@Override public Extensions read(JsonReader in) throws IOException { Extensions extensions;//from ww w .ja v a 2s . c om String str; String name; Extension extension; Class<? extends Extension> clazz; extensions = new Extensions(); in.beginObject(); while (in.peek() == JsonToken.NAME) { str = in.nextName(); name = str.substring(1); clazz = factory.type(name); if (clazz == null) { throw new IOException("extension not found: " + name); } extension = gson.fromJson(in, clazz); extensions.add(name, str.startsWith("+"), extension); } in.endObject(); return extensions; }
From source file:org.apache.axis2.json.gson.GsonXMLStreamReader.java
License:Apache License
private void readValue() throws IOException { nextValue();// ww w. j av a2s . com tokenType = jsonReader.peek(); if (tokenType == JsonToken.NAME) { state = JsonState.ValueName_END; } else if (tokenType == JsonToken.STRING || tokenType == JsonToken.NUMBER || tokenType == JsonToken.BOOLEAN || tokenType == JsonToken.NULL) { state = JsonState.ValueValue_END; } else if (tokenType == JsonToken.END_ARRAY) { state = JsonState.ValueEndArray; } else if (tokenType == JsonToken.END_OBJECT) { state = JsonState.ValueEndObject_END_1; } }
From source file:org.apache.axis2.json.gson.GsonXMLStreamReader.java
License:Apache License
private void readEndObject() throws IOException, XMLStreamException { endObject();/* ww w . j a v a 2 s . co m*/ tokenType = jsonReader.peek(); if (tokenType == JsonToken.END_OBJECT) { removeStackObj(); state = JsonState.EndObjectEndObject; } else if (tokenType == JsonToken.END_ARRAY) { readEndArray(); removeStackObj(); } else if (tokenType == JsonToken.NAME) { removeStackObj(); state = JsonState.EndObjectName; } else if (tokenType == JsonToken.BEGIN_OBJECT) { state = JsonState.EndObjectBeginObject_END; } else if (tokenType == JsonToken.END_DOCUMENT) { removeStackObj(); state = JsonState.EndObjectEndDocument; } }
From source file:org.apache.axis2.json.gson.GsonXMLStreamReader.java
License:Apache License
private void readEndArray() throws IOException { endArray();/*from w w w . ja va 2s . c om*/ tokenType = jsonReader.peek(); if (tokenType == JsonToken.END_OBJECT) { state = JsonState.EndArrayEndObject; } else if (tokenType == JsonToken.NAME) { state = JsonState.EndArrayName; } }
From source file:org.apache.olingo.odata2.core.ep.consumer.JsonErrorDocumentConsumer.java
License:Apache License
private String readJson(final JsonReader reader) throws IOException { StringBuilder sb = new StringBuilder(); while (reader.hasNext()) { JsonToken token = reader.peek(); if (token == JsonToken.NAME) { if (sb.length() > 0) { sb.append(","); }//from w w w .j a va2 s .co m String name = reader.nextName(); sb.append("\"").append(name).append("\"").append(":"); } else if (token == JsonToken.BEGIN_OBJECT) { reader.beginObject(); sb.append("{").append(readJson(reader)).append("}"); reader.endObject(); } else if (token == JsonToken.BEGIN_ARRAY) { reader.beginArray(); sb.append("[").append(readJson(reader)).append("]"); reader.endArray(); } else { sb.append("\"").append(reader.nextString()).append("\""); } } return sb.toString(); }
From source file:org.apache.olingo.odata2.core.ep.util.JsonUtils.java
License:Apache License
public static int startJson(final JsonReader reader) throws EntityProviderException { // The enclosing "d" and "results" are optional - so we cannot check for the presence // but we have to read over them in case they are present. JsonToken token;//from w w w. j av a 2 s. co m try { token = reader.peek(); int openJsonObjects = 0; if (JsonToken.BEGIN_OBJECT == token) { reader.beginObject(); openJsonObjects++; token = reader.peek(); if (JsonToken.NAME == token) { String name = reader.nextName(); if (!("d".equals(name) ^ "results".equals(name))) { // TODO I18N throw new EntityProviderException(EntityProviderException.COMMON, name + " not expected, only d or results"); } } token = reader.peek(); if (JsonToken.BEGIN_OBJECT == token) { reader.beginObject(); openJsonObjects++; } else if (JsonToken.BEGIN_ARRAY == token) { // TODO I18N throw new EntityProviderException(EntityProviderException.COMMON, "Array not expected"); } } return openJsonObjects; } catch (IOException e) { // TODO I18N throw new EntityProviderException(EntityProviderException.COMMON, e); } }