@Test public void testLogRequestParsing_invalidJsonObjectNotClosed() throws IOException { Assert.assertThrows(IOException.class, () -> LogResponse.fromJson(new StringReader("{"))); }
@NonNull public static LogResponse fromJson(@NonNull Reader reader) throws IOException { JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("nextRequestWaitMillis")) { if (jsonReader.peek() == JsonToken.STRING) { return LogResponse.create(Long.parseLong(jsonReader.nextString())); } else { return LogResponse.create(jsonReader.nextLong()); } } jsonReader.skipValue(); } throw new IOException("Response is missing nextRequestWaitMillis field."); } finally { jsonReader.close(); } }
LogResponse { @NonNull public static LogResponse fromJson(@NonNull Reader reader) throws IOException { JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("nextRequestWaitMillis")) { if (jsonReader.peek() == JsonToken.STRING) { return LogResponse.create(Long.parseLong(jsonReader.nextString())); } else { return LogResponse.create(jsonReader.nextLong()); } } jsonReader.skipValue(); } throw new IOException("Response is missing nextRequestWaitMillis field."); } finally { jsonReader.close(); } } }
LogResponse { @NonNull public static LogResponse fromJson(@NonNull Reader reader) throws IOException { JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("nextRequestWaitMillis")) { if (jsonReader.peek() == JsonToken.STRING) { return LogResponse.create(Long.parseLong(jsonReader.nextString())); } else { return LogResponse.create(jsonReader.nextLong()); } } jsonReader.skipValue(); } throw new IOException("Response is missing nextRequestWaitMillis field."); } finally { jsonReader.close(); } }  }
LogResponse { @NonNull public static LogResponse fromJson(@NonNull Reader reader) throws IOException { JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("nextRequestWaitMillis")) { if (jsonReader.peek() == JsonToken.STRING) { return LogResponse.create(Long.parseLong(jsonReader.nextString())); } else { return LogResponse.create(jsonReader.nextLong()); } } jsonReader.skipValue(); } throw new IOException("Response is missing nextRequestWaitMillis field."); } finally { jsonReader.close(); } }  abstract long getNextRequestWaitMillis(); @NonNull static LogResponse fromJson(@NonNull Reader reader); }
LogResponse { @NonNull public static LogResponse fromJson(@NonNull Reader reader) throws IOException { JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals("nextRequestWaitMillis")) { if (jsonReader.peek() == JsonToken.STRING) { return LogResponse.create(Long.parseLong(jsonReader.nextString())); } else { return LogResponse.create(jsonReader.nextLong()); } } jsonReader.skipValue(); } throw new IOException("Response is missing nextRequestWaitMillis field."); } finally { jsonReader.close(); } }  abstract long getNextRequestWaitMillis(); @NonNull static LogResponse fromJson(@NonNull Reader reader);  }