List of usage examples for com.google.gson.stream JsonToken END_OBJECT
JsonToken END_OBJECT
To view the source code for com.google.gson.stream JsonToken END_OBJECT.
Click Source Link
From source file:ddt.dtool.util.JsonReaderExt.java
License:Open Source License
public static HashMap<String, Object> readJsonObject(JsonReaderExt jsonParser) throws IOException { jsonParser.consumeExpected(JsonToken.BEGIN_OBJECT); HashMap<String, Object> jsonObject = new HashMap<>(); while (jsonParser.tryConsume(JsonToken.END_OBJECT) == false) { String propName = jsonParser.consumeExpectedPropName(); Object propvalue = readJsonValue(jsonParser); jsonObject.put(propName, propvalue); }/* ww w . jav a2 s . co m*/ return jsonObject; }
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();/*from w w w .j a v a 2s .c o m*/ } } 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 w w w. j ava 2s. c o m } } else { jsonReader.errorUnexpected(tokenType); } } jsonReader.consumeExpected(JsonToken.END_OBJECT); return this; }
From source file:dtool.dub.DubManifestParser.java
License:Open Source License
protected DubConfiguration parseConfiguration(JsonReaderExt jsonReader) throws IOException, DubBundleException { jsonReader.consumeExpected(JsonToken.BEGIN_OBJECT); String name = null;/*from w ww . j a v a2s .co m*/ String targetType = null; String targetName = null; String targetPath = null; while (jsonReader.hasNext()) { String propName = jsonReader.consumeExpectedPropName(); switch (propName) { case "name": name = jsonReader.consumeStringValue(); break; case "targetType": targetType = jsonReader.consumeStringValue(); break; case "targetName": targetName = jsonReader.consumeStringValue(); break; case "targetPath": targetPath = jsonReader.consumeStringValue(); break; default: jsonReader.skipValue(); } } jsonReader.consumeExpected(JsonToken.END_OBJECT); if (name == null) { throw new DubBundleException("Build configuration has no name attribute"); } return new DubConfiguration(name, targetType, targetName, targetPath); }
From source file:io.grpc.internal.JsonParser.java
License:Apache License
private static Map<String, ?> parseJsonObject(JsonReader jr) throws IOException { jr.beginObject();/* www. j a v a 2s. c o m*/ Map<String, Object> obj = new LinkedHashMap<>(); while (jr.hasNext()) { String name = jr.nextName(); Object value = parseRecursive(jr); obj.put(name, value); } checkState(jr.peek() == JsonToken.END_OBJECT, "Bad token: " + jr.getPath()); jr.endObject(); return Collections.unmodifiableMap(obj); }
From source file:json.tests.reader.JSONStreamReader.java
License:Open Source License
/** * Move the pointer to the next required element of the json stream. * //ww w . ja v a 2 s. c o m * @param skip Flag indicating whether the current object is a required element * @param isStartElement Flag indicating whether to traverse inside the object or not. Value for this is * 'true' when this method is called by {@link #beginObject()} or {@link #beginArray()} * methods. * @throws IOException */ private void goToNextToken(boolean skip, boolean isStartElement) throws IOException { while (super.hasNext()) { this.hasNext = true; this.lastToken = this.currentToken; this.currentToken = super.peek(); switch (this.currentToken) { case BEGIN_OBJECT: if (skip) { super.skipValue(); popNonAnonymousObject(); break; } handleObject(skip, isStartElement); return; case BEGIN_ARRAY: if (skip) { super.skipValue(); popNonAnonymousObject(); break; } handleArray(skip, isStartElement); return; case NAME: this.currentElementName = super.nextName(); skip = !isRequired(this.currentElementName); // Whenever a element name is read, add it to the stack. this.elementsStack.push(new JsonElement(this.currentElementName, null)); this.isNextObjectAnonymous = false; if (!skip) { return; } break; case NUMBER: popPrimitive(); if (!skip) { /* * Number can be int/long/double. hence reading it as string, and then parsing it * to the corresponding type, during #next****() method. */ this.currentElementValue = super.nextString(); return; } super.skipValue(); break; case STRING: popPrimitive(); if (!skip) { this.currentElementValue = super.nextString(); return; } super.skipValue(); break; case BOOLEAN: popPrimitive(); if (!skip) { this.currentElementValue = super.nextBoolean(); return; } super.skipValue(); break; case END_DOCUMENT: this.hasNext = false; return; default: super.skipValue(); } isStartElement = false; } // when exiting the current element, set the current token type to END_OBJECT/END_ARRAY if (!this.elementsStack.isEmpty()) { ElementType startedElementType = this.elementsStack.peek().getType(); if (startedElementType == ElementType.OBJECT) { this.currentToken = JsonToken.END_OBJECT; } else if (startedElementType == ElementType.ARRAY) { this.currentToken = JsonToken.END_ARRAY; } } this.hasNext = false; }
From source file:net.hft.dbproject.weatherapp.services.JSONParser.java
/** * Parsingmethod for the single JSON- Objects. * * @return Parsed Location//from w w w. j av a 2 s. co m */ private static Location toLocation() { Location result = new Location(); String cityName = ""; Temperature cityTemperature = null; double tempAvg = 0.0; double tempMin = 0.0; double tempMax = 0.0; String countryCode = ""; int imageIconID = 0; int ident = 0; boolean isDayImage = false; String weatherDescription = ""; // GPS- Coordinates float lat = 0, lon = 0; try { int passedCounter = 0; while (queryJSONReader.hasNext() && passedCounter < 6) { while (passedCounter < 6) { String selectedValue = singleObject ? "coord" : queryJSONReader.nextName(); switch (selectedValue) { case "id": { ident = queryJSONReader.nextInt(); passedCounter++; break; } case "name": { cityName = queryJSONReader.nextString(); passedCounter++; break; } case "coord": { queryJSONReader.beginObject(); while (queryJSONReader.hasNext()) { String name2 = queryJSONReader.nextName(); if (name2.equals("lon")) { lon = (float) queryJSONReader.nextDouble(); name2 = queryJSONReader.nextName(); } if (name2.equals("lat")) { lat = (float) queryJSONReader.nextDouble(); } queryJSONReader.endObject(); singleObject = false; passedCounter++; break; } break; } case "main": { queryJSONReader.beginObject(); while (queryJSONReader.hasNext()) { String attribute = queryJSONReader.nextName(); if (attribute.equals("temp")) { tempAvg = Utilities.fromKelvinToFahrenheit(queryJSONReader.nextDouble()); } else if (attribute.equals("temp_min")) { tempMin = Utilities.fromKelvinToFahrenheit(queryJSONReader.nextDouble()); } else if (attribute.equals("temp_max")) { tempMax = Utilities.fromKelvinToFahrenheit(queryJSONReader.nextDouble()); } else { queryJSONReader.skipValue(); } } queryJSONReader.endObject(); cityTemperature = new Temperature(tempAvg, tempMin, tempMax); passedCounter++; break; } case "sys": { queryJSONReader.beginObject(); while (queryJSONReader.hasNext()) { String attribute = queryJSONReader.nextName(); if (attribute.equals("country")) { countryCode = queryJSONReader.nextString(); } else { queryJSONReader.skipValue(); } } queryJSONReader.endObject(); passedCounter++; break; } case "weather": { queryJSONReader.beginArray(); queryJSONReader.beginObject(); while (queryJSONReader.hasNext()) { String attribute = queryJSONReader.nextName(); if (attribute.equals("id")) { imageIconID = queryJSONReader.nextInt(); } else if (attribute.equals("description")) { weatherDescription = queryJSONReader.nextString(); } else if (attribute.equals("icon")) { String val = queryJSONReader.nextString(); if (val.endsWith("d")) { isDayImage = true; } } else { queryJSONReader.skipValue(); } } queryJSONReader.endObject(); JsonToken t = queryJSONReader.peek(); if (t == JsonToken.BEGIN_OBJECT) { queryJSONReader.beginObject(); while (t != JsonToken.END_OBJECT) { String v = queryJSONReader.nextName(); queryJSONReader.skipValue(); t = queryJSONReader.peek(); } queryJSONReader.endObject(); } queryJSONReader.endArray(); passedCounter++; break; } default: { queryJSONReader.skipValue(); } } } result = new Location(ident, cityName, countryCode, cityTemperature, lat, lon); result.setWeatherDescription(weatherDescription); WeatherImage wi = new WeatherImage(); result.setDayTime(isDayImage); wi.setIconId(imageIconID); result.setImage(wi); } } catch (IOException ex) { LOGGER.error(ex.toString()); } return result; }
From source file:org.apache.axis2.json.gson.GsonXMLStreamReader.java
License:Apache License
private void readValue() throws IOException { nextValue();//from ww w . j a va2 s. c o m 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 va2s . com*/ 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();/*w ww . j a va2 s.co m*/ tokenType = jsonReader.peek(); if (tokenType == JsonToken.END_OBJECT) { state = JsonState.EndArrayEndObject; } else if (tokenType == JsonToken.NAME) { state = JsonState.EndArrayName; } }