List of usage examples for com.google.gson.stream JsonReader beginObject
public void beginObject() throws IOException
From source file:com.epickrram.romero.testing.server.web.CompletedJobRunIdentifierTypeAdapter.java
License:Apache License
@Override public CompletedJobRunIdentifier read(final JsonReader jsonReader) throws IOException { jsonReader.beginObject(); final CompletedJobRunIdentifier.Builder builder = new CompletedJobRunIdentifier.Builder(); while (jsonReader.hasNext()) { final String name = jsonReader.nextName(); if ("jobRunIdentifier".equals(name)) { builder.jobRunIdentifier(jsonReader.nextString()); } else if ("startTimestamp".equals(name)) { builder.startTimestamp(jsonReader.nextLong()); }/*from w w w . j a v a 2 s . co m*/ } jsonReader.endObject(); return builder.create(); }
From source file:com.facebook.buck.worker.WorkerProcessProtocolZero.java
License:Apache License
private static void receiveHandshake(JsonReader reader, int messageId, Optional<Path> stdErr) throws IOException { int id = -1;/*from w w w . j a v a 2s .co m*/ String type = ""; String protocolVersion = ""; try { reader.beginArray(); reader.beginObject(); while (reader.hasNext()) { String property = reader.nextName(); if (property.equals("id")) { id = reader.nextInt(); } else if (property.equals("type")) { type = reader.nextString(); } else if (property.equals("protocol_version")) { protocolVersion = reader.nextString(); } else if (property.equals("capabilities")) { try { reader.beginArray(); reader.endArray(); } catch (IllegalStateException e) { throw new HumanReadableException( "Expected handshake response's \"capabilities\" to " + "be an empty array."); } } else { reader.skipValue(); } } reader.endObject(); } catch (IOException e) { throw new HumanReadableException(e, "Error receiving handshake response from external process.\n" + "Stderr from external process:\n%s", getStdErrorOutput(stdErr)); } if (id != messageId) { throw new HumanReadableException(String.format( "Expected handshake response's \"id\" value " + "to be \"%d\", got \"%d\" instead.", messageId, id)); } if (!type.equals(TYPE_HANDSHAKE)) { throw new HumanReadableException( String.format("Expected handshake response's \"type\" " + "to be \"%s\", got \"%s\" instead.", TYPE_HANDSHAKE, type)); } if (!protocolVersion.equals(PROTOCOL_VERSION)) { throw new HumanReadableException(String.format( "Expected handshake response's " + "\"protocol_version\" to be \"%s\", got \"%s\" instead.", PROTOCOL_VERSION, protocolVersion)); } }
From source file:com.flipkart.batchdemo.adapter.CustomTagDataAdapter.java
License:Open Source License
@Override public CustomTagData read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();//from ww w .jav a2 s . com return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); Tag tag = null; Long eventId = 0L; JSONObject event = null; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "tag": tag = tagTypeAdapter.read(reader); break; case "eventId": eventId = BatchingTypeAdapters.LONG.read(reader); break; case "event": event = BatchingTypeAdapters.getJSONObjectTypeAdapter(gson).read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); CustomTagData customTagData = new CustomTagData(tag, event); customTagData.setEventId(eventId); return customTagData; }
From source file:com.flipkart.batching.gson.adapters.batch.SizeBatchTypeAdapter.java
License:Open Source License
@Override public SizeBatch<T> read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from w w w. j a v a2 s . co m*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); int maxBatchSize = 0; DataCollection<T> dataCollection = null; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "maxBatchSize": maxBatchSize = BatchingTypeAdapters.INTEGER.read(reader); break; case "dataCollection": dataCollection = typeAdapter.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return dataCollection == null ? null : new SizeBatch<>(dataCollection.dataCollection, maxBatchSize); }
From source file:com.flipkart.batching.gson.adapters.batch.SizeTimeBatchTypeAdapter.java
License:Open Source License
@Override public SizeTimeBatch<T> read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();// w ww . ja va2 s . c o m return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); int maxBatchSize = 0; DataCollection<T> dataCollection = null; long timeout = 0L; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "maxBatchSize": maxBatchSize = BatchingTypeAdapters.INTEGER.read(reader); break; case "dataCollection": dataCollection = typeAdapter.read(reader); break; case "timeOut": timeout = BatchingTypeAdapters.LONG.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return dataCollection == null ? null : new SizeTimeBatch<>(dataCollection.dataCollection, maxBatchSize, timeout); }
From source file:com.flipkart.batching.gson.adapters.batch.TagBatchTypeAdapter.java
License:Open Source License
@Override public TagBatch<T> read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from w w w . j a va 2 s .c om*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); Tag tag = null; DataCollection<T> collection = null; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "tag": tag = tagTypeAdapter.read(reader); break; case "dataCollection": collection = typeAdapter.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return collection == null || tag == null ? null : new TagBatch<>(tag, new BatchImpl<>(collection.dataCollection)); }
From source file:com.flipkart.batching.gson.adapters.batch.TimeBatchTypeAdapter.java
License:Open Source License
@Override public TimeBatch<T> read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from w w w .ja v a 2 s.c om*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); long timeOut = 0L; DataCollection<T> dataCollection = null; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "timeOut": timeOut = BatchingTypeAdapters.LONG.read(reader); break; case "dataCollection": dataCollection = typeAdapter.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return dataCollection == null ? null : new TimeBatch<>(dataCollection.dataCollection, timeOut); }
From source file:com.flipkart.batching.gson.adapters.BatchImplTypeAdapter.java
License:Open Source License
@Override public BatchImpl<T> read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from w w w . ja v a2 s.c om*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); DataCollection<T> dataCollection = null; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "dataCollection": dataCollection = typeAdapter.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); return dataCollection == null ? null : new BatchImpl<T>(dataCollection.dataCollection); }
From source file:com.flipkart.batching.gson.adapters.data.EventDataTypeAdapter.java
License:Open Source License
@Override public EventData read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from w ww . j a v a 2 s . co m*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); EventData object = new EventData(); while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "eventId": object.setEventId(BatchingTypeAdapters.LONG.read(reader)); break; default: reader.skipValue(); break; } } reader.endObject(); return object; }
From source file:com.flipkart.batching.gson.adapters.data.TagDataTypeAdapter.java
License:Open Source License
@Override public TagData read(JsonReader reader) throws IOException { if (reader.peek() == com.google.gson.stream.JsonToken.NULL) { reader.nextNull();/*from www .jav a2s . c o m*/ return null; } if (reader.peek() != com.google.gson.stream.JsonToken.BEGIN_OBJECT) { reader.skipValue(); return null; } reader.beginObject(); Tag tag = null; long eventId = 0L; while (reader.hasNext()) { String name = reader.nextName(); com.google.gson.stream.JsonToken jsonToken = reader.peek(); if (jsonToken == com.google.gson.stream.JsonToken.NULL) { reader.skipValue(); continue; } switch (name) { case "tag": tag = tagTypeAdapter.read(reader); break; case "eventId": eventId = BatchingTypeAdapters.LONG.read(reader); break; default: reader.skipValue(); break; } } reader.endObject(); TagData tagData = new TagData(tag); tagData.setEventId(eventId); return tagData; }