ImmutableSearchResult implements SearchResult { public static ImmutableSearchResult fromJson(final JsonObject jsonObject) { final JsonArray extractedItems = jsonObject.getValueOrThrow(JsonFields.ITEMS); final Long extractedNextPageOffset = jsonObject.getValue(JsonFields.NEXT_PAGE_OFFSET).orElse(null); final String extractedCursor = jsonObject.getValue(JsonFields.CURSOR).orElse(null); return of(extractedItems, extractedNextPageOffset, extractedCursor); } private  ImmutableSearchResult(final JsonArray items, @Nullable final Long nextPageOffset,
            @Nullable final String cursor); static SearchResult empty(); static ImmutableSearchResult of(final JsonArray items,
            @Nullable final Long nextPageOffset,
            @Nullable final String cursor); static ImmutableSearchResult fromJson(final JsonObject jsonObject); @Override JsonArray getItems(); @Override Optional<Long> getNextPageOffset(); @Override Optional<String> getCursor(); @Override boolean hasNextPage(); @Override int getSize(); @Override boolean isEmpty(); @Override Stream<JsonValue> stream(); @Override Iterator<JsonValue> iterator(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void fromJson() { final String itemsArray = "[1,2,3]"; final long nextPageOffset = 10L; final String jsonStr = "{\"items\":" + itemsArray + ",\"nextPageOffset\":" + nextPageOffset + "}"; final JsonObject jsonObject = JsonFactory.newObject(jsonStr); final SearchResult searchResult = ImmutableSearchResult.fromJson(jsonObject); assertThat(searchResult.getItems()).isEqualTo(JsonFactory.newArray(itemsArray)); assertThat(searchResult.getNextPageOffset()).contains(nextPageOffset); }