List of usage examples for com.google.gson.stream JsonReader endObject
public void endObject() throws IOException
From source file:org.guvnor.ala.openshift.access.OpenShiftRuntimeId.java
License:Apache License
public static OpenShiftRuntimeId fromString(String s) { String project = null;//from w w w . j av a2 s.c om String service = null; String application = null; try { JsonReader jr = new JsonReader(new StringReader(s)); jr.beginObject(); while (jr.hasNext()) { String n = jr.nextName(); if (PROJECT.equals(n)) { project = jr.nextString(); } else if (SERVICE.equals(n)) { service = jr.nextString(); } else if (APPLICATION.equals(n)) { application = jr.nextString(); } else { jr.skipValue(); } } jr.endObject(); jr.close(); } catch (IOException ex) { throw new RuntimeException(ex.getMessage(), ex); } return new OpenShiftRuntimeId(project, service, application); }
From source file:org.gw2InfoViewer.services.json.JsonConversionService.java
License:Open Source License
public static EventList parseEventListWithoutNames(InputStream json) throws IOException { List<Event> events; events = new ArrayList<Event>(); JsonReader reader = new JsonReader(new InputStreamReader(json)); reader.beginObject();/*from w w w. j a v a2 s. co m*/ if (reader.nextName().equals("events")) { reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { Event event = gsonBuilder.create().fromJson(reader, Event.class); events.add(event); } reader.endArray(); reader.endObject(); } return new EventList(events); }
From source file:org.gw2InfoViewer.services.json.typeadaptors.EventAdapter.java
License:Open Source License
@Override public Event read(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.NULL) { reader.nextNull();/*from w w w .j a v a2s . com*/ return null; } Event event = new Event(); reader.beginObject(); reader.nextName(); //world id event.setWorldId(reader.nextInt()); reader.nextName(); //map id event.setMapId(reader.nextInt()); reader.nextName(); //event id event.setEventId(reader.nextString()); reader.nextName(); event.setState(EventState.valueOf(reader.nextString())); //state reader.endObject(); return event; }
From source file:org.hibernate.search.backend.elasticsearch.gson.impl.AbstractExtraPropertiesJsonAdapter.java
License:LGPL
@Override public T read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();//from w w w . j a va 2 s . c o m return null; } T instance = createInstance(); try { in.beginObject(); while (in.hasNext()) { String name = in.nextName(); FieldAdapter<? super T> fieldAdapter = fieldAdapters.get(name); if (fieldAdapter == null) { extraPropertyAdapter.readOne(in, name, instance); } else { fieldAdapter.read(in, instance); } } in.endObject(); } catch (IllegalStateException e) { throw new JsonSyntaxException(e); } return instance; }
From source file:org.hillview.table.rows.GuessSchema.java
License:Open Source License
/** * Throws if the value is not valid JSON * The gson parser is not strict enough: it parses * unquoted strings as JSON.String, so we have to do this manually. * Returns true if this is a complex json value, false otherwise. *///w ww. ja va2 s.c om private static boolean isJsonValid(final JsonReader jsonReader) throws IOException { JsonToken token; boolean isComplex = false; loop: while ((token = jsonReader.peek()) != JsonToken.END_DOCUMENT && token != null) { switch (token) { case BEGIN_ARRAY: isComplex = true; jsonReader.beginArray(); break; case END_ARRAY: isComplex = true; jsonReader.endArray(); break; case BEGIN_OBJECT: isComplex = true; jsonReader.beginObject(); break; case END_OBJECT: isComplex = true; jsonReader.endObject(); break; case NAME: jsonReader.nextName(); break; case STRING: case NUMBER: case BOOLEAN: case NULL: jsonReader.skipValue(); break; case END_DOCUMENT: break loop; default: throw new AssertionError(token); } } return isComplex; }
From source file:org.imperiumstudios.Imperium1871Bungee.BukkitWarpHelper.files.JsonFile.java
License:Open Source License
/** * Read the config File into RAM.//from w w w .ja v a2s .c o m */ public void readFile() { try { JsonReader reader = new JsonReader(new FileReader(jsonFile)); reader.beginObject(); while (reader.hasNext()) jsonFileContent.put(reader.nextName(), reader.nextString()); reader.endObject(); reader.close(); } catch (IOException ex) { IMP.log.error("JsonFile.java > readFile() > Unable to read " + jsonFile + ". Disabling this plugin .."); IMP.log.error("JsonFile.java > readFile() > Error: " + ex.getMessage()); IMP.disable(); } }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
public List<CordovaRegistryPluginInfo> retrievePluginInfos(IProgressMonitor monitor) throws CoreException { if (monitor == null) monitor = new NullProgressMonitor(); HttpClient client = new DefaultHttpClient(); String url = registry.endsWith("/") ? registry + "-/all" : registry + "/-/all"; HttpGet get = new HttpGet(url); HttpResponse response;//w w w .j a va 2 s . c o m try { if (monitor.isCanceled()) { return null; } response = client.execute(get); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); monitor.worked(9); JsonReader reader = new JsonReader(new InputStreamReader(stream)); reader.beginObject();//start the Registry plugins = new ArrayList<CordovaRegistryPluginInfo>(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_OBJECT: CordovaRegistryPluginInfo info = new CordovaRegistryPluginInfo(); readPluginInfo(reader, info); plugins.add(info); break; case NAME: String name = reader.nextName(); if (name.equals("_updated")) { long newUpdate = reader.nextLong(); if (newUpdate == this.updated) {//No changes return plugins; } } break; default: Assert.isTrue(false, "Unexpected token: " + token); break; } } reader.endObject(); return plugins; } catch (ClientProtocolException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e)); } catch (IOException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e)); } finally { monitor.done(); } }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void readPluginInfo(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException { Assert.isNotNull(plugin);/*from w w w.j a va2 s . c o m*/ reader.beginObject(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case NAME: { String name = reader.nextName(); if ("name".equals(name)) { plugin.setName(reader.nextString()); break; } if ("description".equals(name)) { plugin.setDescription(reader.nextString()); break; } if ("keywords".equals(name)) { parseKeywords(reader, plugin); break; } if ("maintainers".equals(name)) { parseMaintainers(reader, plugin); break; } if ("dist-tags".equals(name)) { parseLatestVersion(reader, plugin); break; } if ("versions".equals(name) && plugin instanceof CordovaRegistryPlugin) { parseDetailedVersions(reader, (CordovaRegistryPlugin) plugin); break; } if ("dist".equals(name) && plugin instanceof CordovaRegistryPluginVersion) { parseDistDetails(reader, (CordovaRegistryPluginVersion) plugin); break; } if ("license".equals(name) && plugin instanceof CordovaRegistryPluginVersion) { CordovaRegistryPluginVersion v = (CordovaRegistryPluginVersion) plugin; v.setLicense(reader.nextString()); break; } break; } default: reader.skipValue(); break; } } reader.endObject(); }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void parseDistDetails(JsonReader reader, CordovaRegistryPluginVersion plugin) throws IOException { reader.beginObject();//from w ww .j ava 2 s. co m JsonToken token = reader.peek(); while (token != JsonToken.END_OBJECT) { switch (token) { case NAME: String name = reader.nextName(); if ("shasum".equals(name)) { plugin.setDistributionSHASum(reader.nextString()); break; } if ("tarball".equals(name)) { plugin.setDistributionTarball(reader.nextString()); break; } break; default: reader.skipValue(); break; } token = reader.peek(); } reader.endObject(); }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void parseDetailedVersions(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException { reader.beginObject();//versions JsonToken token = reader.peek();//from w ww. j a v a 2 s . co m while (token != JsonToken.END_OBJECT) { switch (token) { case NAME: CordovaRegistryPluginVersion version = new CordovaRegistryPluginVersion(); version.setVersionNumber(reader.nextName()); readPluginInfo(reader, version); plugin.addVersion(version); break; default: reader.skipValue(); break; } token = reader.peek(); } reader.endObject(); }