List of usage examples for com.google.gson.stream JsonReader nextString
public String nextString() throws IOException
From source file:org.jclouds.glesys.functions.internal.GlesysDateAdapter.java
License:Apache License
public Date read(JsonReader reader) throws IOException { String toParse = reader.nextString(); try {/*from w w w . j a v a 2 s . com*/ return standardDateService.iso8601SecondsDateParse(toParse); } catch (Exception ex) { try { synchronized (dateFormat) { return dateFormat.parse(toParse); } } catch (ParseException e) { throw Throwables.propagate(e); } } }
From source file:org.jclouds.http.functions.ParseFirstJsonValueNamed.java
License:Apache License
private JsonToken skipAndPeek(JsonToken token, JsonReader reader) throws IOException { switch (token) { case BEGIN_ARRAY: reader.beginArray();//from www . j av a 2 s . c o m break; case END_ARRAY: reader.endArray(); break; case BEGIN_OBJECT: reader.beginObject(); break; case END_OBJECT: reader.endObject(); break; case NAME: // NOTE that we have already advanced on NAME in the eval block; break; case STRING: reader.nextString(); break; case NUMBER: reader.nextString(); break; case BOOLEAN: reader.nextBoolean(); break; case NULL: reader.nextNull(); break; case END_DOCUMENT: break; } return reader.peek(); }
From source file:org.jclouds.oauth.v2.json.ClaimSetTypeAdapter.java
License:Apache License
@Override public ClaimSet read(JsonReader in) throws IOException { ClaimSet.Builder builder = new ClaimSet.Builder(); in.beginObject();/* w ww . jav a 2 s. c o m*/ while (in.hasNext()) { String claimName = in.nextName(); String claimValue = in.nextString(); builder.addClaim(claimName, claimValue); } in.endObject(); return builder.build(); }
From source file:org.jclouds.oauth.v2.json.HeaderTypeAdapter.java
License:Apache License
@Override public Header read(JsonReader in) throws IOException { Header.Builder builder = new Header.Builder(); in.beginObject();//from w w w . j av a2 s. c om in.nextName(); builder.signerAlgorithm(in.nextString()); in.nextName(); builder.type(in.nextString()); in.endObject(); return builder.build(); }
From source file:org.jclouds.openstack.swift.v1.config.SwiftTypeAdapters.java
License:Apache License
static void readErrors(JsonReader reader, Builder<String, String> errors) throws IOException { reader.beginArray();//from w ww .j a v a 2s .c o m while (reader.hasNext()) { reader.beginArray(); String decodedPath = URI.create(reader.nextString()).getPath(); errors.put(decodedPath, reader.nextString()); reader.endArray(); } reader.endArray(); }
From source file:org.jsfr.json.GsonParser.java
License:Open Source License
private ResumableParser createResumableParserImpl(Reader reader, SurfingContext context) { final JsonReader jsonReader = this.jsonReaderFactory.createJsonReader(reader); final JsonProvider jsonProvider = context.getConfig().getJsonProvider(); AbstractPrimitiveHolder stringHolder = new AbstractPrimitiveHolder(context.getConfig()) { @Override/*from ww w. j ava2 s .co m*/ public Object doGetValue() throws IOException { return jsonProvider.primitive(jsonReader.nextString()); } @Override public void doSkipValue() throws IOException { jsonReader.skipValue(); } }; AbstractPrimitiveHolder numberHolder = new AbstractPrimitiveHolder(context.getConfig()) { @Override public Object doGetValue() throws IOException { return jsonProvider.primitive(jsonReader.nextDouble()); } @Override public void doSkipValue() throws IOException { jsonReader.skipValue(); } }; AbstractPrimitiveHolder booleanHolder = new AbstractPrimitiveHolder(context.getConfig()) { @Override public Object doGetValue() throws IOException { return jsonProvider.primitive(jsonReader.nextBoolean()); } @Override public void doSkipValue() throws IOException { jsonReader.skipValue(); } }; AbstractPrimitiveHolder nullHolder = new AbstractPrimitiveHolder(context.getConfig()) { @Override public Object doGetValue() throws IOException { jsonReader.nextNull(); return jsonProvider.primitiveNull(); } @Override public void doSkipValue() throws IOException { jsonReader.skipValue(); } }; return new GsonResumableParser(jsonReader, context, stringHolder, numberHolder, booleanHolder, nullHolder); }
From source file:org.kairosdb.client.AbstractClient.java
License:Apache License
private List<String> readNameQueryResponse(InputStream stream) throws IOException { List<String> list = new ArrayList<String>(); JsonReader reader = new JsonReader(new InputStreamReader(stream, "UTF-8")); try {//from w w w.ja v a 2 s .c o m reader.beginObject(); String container = reader.nextName(); if (container.equals("results")) { reader.beginArray(); while (reader.hasNext()) { list.add(reader.nextString()); } reader.endArray(); reader.endObject(); } } finally { reader.close(); } return list; }
From source file:org.komodo.rest.json.LinkSerializer.java
License:Open Source License
/** * {@inheritDoc}/*from w ww .j a va2 s . com*/ * * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader) */ @Override public RestLink read(final JsonReader in) throws IOException { final RestLink link = new RestLink(); in.beginObject(); while (in.hasNext()) { final String name = in.nextName(); switch (name) { case JsonConstants.HREF: final String uri = in.nextString(); link.setHref(UriBuilder.fromUri(uri).build()); break; case JsonConstants.REL: final String rel = in.nextString(); link.setRel(LinkType.fromString(rel)); break; default: throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name)); } } in.endObject(); if (!isComplete(link)) { throw new IOException(Messages.getString(INCOMPLETE_JSON, RestVdbImport.class.getSimpleName())); } return link; }
From source file:org.komodo.rest.json.RestPropertySerializer.java
License:Open Source License
@Override public RestProperty read(JsonReader in) throws IOException { String propName = null;/*www. j ava 2 s . c om*/ Object propValue = null; in.beginObject(); while (in.hasNext()) { String name = in.nextName(); if (RestProperty.NAME_LABEL.equals(name)) propName = in.nextString(); else if (RestProperty.VALUE_LABEL.equals(name)) { JsonToken token = in.peek(); switch (token) { case BOOLEAN: propValue = in.nextBoolean(); break; case NUMBER: { double value = in.nextDouble(); if (value % 1 == 0) propValue = (int) value; else propValue = value; break; } case STRING: propValue = in.nextString(); break; case NULL: in.nextNull(); propValue = null; break; case BEGIN_ARRAY: final Object[] value = BUILDER.fromJson(in, Object[].class); // // BUILDER always converts json numbers to double regardless // of them being integers so need to do some checking and on-the-fly // conversion // for (int i = 0; i < value.length; ++i) { if (value[i] instanceof Double && ((double) value[i] % 1) == 0) value[i] = ((Double) value[i]).intValue(); } propValue = value; break; default: throw new IOException(Messages.getString(Messages.Error.UNEXPECTED_JSON_TOKEN, name)); } } } in.endObject(); RestProperty property = new RestProperty(propName, propValue); if (!isComplete(property)) throw new IOException( Messages.getString(Messages.Error.INCOMPLETE_JSON, RestProperty.class.getSimpleName())); return property; }
From source file:org.komodo.rest.relational.json.AbstractContentSerializer.java
License:Open Source License
protected String readContent(final JsonReader in, final AbstractKomodoContentAttribute contentAttr, final String name) throws IOException { if (AbstractKomodoContentAttribute.CONTENT_LABEL.equals(name)) { contentAttr.setContent(in.nextString()); return name; }//from w ww . j a va 2 s .co m return null; }