public static <T> boolean read(JsonReaderAdapter<T> adapter, byte[] bytes, Collection<T> out) { if (bytes.length == 0) return false; try { out.add(adapter.fromJson(new JsonReader(bytes))); return true; } catch (Exception e) { throw exceptionReading(adapter.toString(), e); } }
builder.duration(reader.nextLong()); } else if (nextName.equals("localEndpoint")) { builder.localEndpoint(ENDPOINT_READER.fromJson(reader)); } else if (nextName.equals("remoteEndpoint")) { builder.remoteEndpoint(ENDPOINT_READER.fromJson(reader)); } else if (nextName.equals("annotations")) { reader.beginArray();
endpoint = ENDPOINT_READER.fromJson(reader); } else { reader.skipValue();
void readAnnotation(JsonReader reader) throws IOException { String nextName; reader.beginObject(); Long timestamp = null; String value = null; Endpoint endpoint = null; while (reader.hasNext()) { nextName = reader.nextName(); if (nextName.equals("timestamp")) { timestamp = reader.nextLong(); } else if (nextName.equals("value")) { value = reader.nextString(); } else if (nextName.equals("endpoint") && !reader.peekNull()) { endpoint = ENDPOINT_READER.fromJson(reader); } else { reader.skipValue(); } } if (timestamp == null || value == null) { throw new IllegalArgumentException("Incomplete annotation at " + reader.getPath()); } reader.endObject(); builder.addAnnotation(timestamp, value, endpoint); }
public static <T> boolean readList( JsonReaderAdapter<T> adapter, byte[] bytes, Collection<T> out) { if (bytes.length == 0) return false; JsonReader reader = new JsonReader(bytes); try { reader.beginArray(); if (!reader.hasNext()) return false; while (reader.hasNext()) out.add(adapter.fromJson(reader)); reader.endArray(); return true; } catch (Exception e) { throw exceptionReading("List<" + adapter + ">", e); } }