Deferred implements ScheduleData { @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public static Deferred fromJson(@NonNull JsonValue jsonValue) throws JsonException { String urlString = jsonValue.optMap().opt(URL_KEY).getString(); if (urlString == null) { throw new JsonException("Missing URL"); } URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { throw new JsonException("Invalid URL " + urlString, e); } boolean retryOnTimeout = jsonValue.optMap().opt(RETRY_ON_TIMEOUT).getBoolean(true); return new Deferred(url, retryOnTimeout); } Deferred(@NonNull URL url, boolean retryOnTimeout); @NonNull URL getUrl(); boolean isRetriableOnTimeout(); @NonNull @Override JsonValue toJsonValue(); @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) static Deferred fromJson(@NonNull JsonValue jsonValue); @Override boolean equals(Object o); @Override int hashCode(); public URL url; public boolean retryOnTimeout; }
@Test public void testFromJson() throws JsonException, MalformedURLException { JsonValue jsonValue = JsonMap.newBuilder() .put("url", "https: .put("retry_on_timeout", false) .build() .toJsonValue(); Deferred deferred = Deferred.fromJson(jsonValue); assertEquals(new URL("https: assertFalse(deferred.isRetriableOnTimeout()); }