Document implements Serializable { @SuppressWarnings("unchecked") public <DATA extends ResourceIdentifier> ArrayDocument<DATA> asArrayDocument() { if (this instanceof ArrayDocument) { return ((ArrayDocument<DATA>) this); } else if (this instanceof ObjectDocument) { ArrayDocument<DATA> document = new ArrayDocument<>(this); DATA data = ((ObjectDocument<DATA>) this).get(); if (data != null) { document.add(data); } return document; } throw new AssertionError("unexpected document type"); } Document();  Document(Document document); @Deprecated boolean include(Resource resource); @Deprecated boolean exclude(Resource resource); boolean addInclude(Resource resource); Collection<Resource> getIncluded(); @SuppressWarnings({"SuspiciousMethodCalls", "unchecked"}) T find(ResourceIdentifier resourceIdentifier); T find(String type, String id); @Deprecated boolean errors(List<Error> errors); @Deprecated List<Error> errors(); boolean addError(Error error); boolean setErrors(Collection<Error> errors); List<Error> getErrors(); boolean hasError(); JsonBuffer getMeta(); void setMeta(JsonBuffer meta); JsonBuffer getLinks(); void setLinks(JsonBuffer links); JsonBuffer getJsonApi(); void setJsonApi(JsonBuffer jsonApi); @SuppressWarnings("unchecked") ArrayDocument<DATA> asArrayDocument(); ObjectDocument<DATA> asObjectDocument(); @SuppressWarnings("unchecked") ObjectDocument<DATA> asObjectDocument(int position); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void deserialize_multiple_empty() throws Exception { Document document = getDocumentAdapter(Article.class) .fromJson(TestUtil.fromResource("/multiple_empty.json")); assertThat(document, instanceOf(ArrayDocument.class)); ArrayDocument<Article> arrayDocument = document.asArrayDocument(); assertTrue(arrayDocument.isEmpty()); }
@Test public void deserialize_multiple_polymorphic() throws Exception { Document document = getDocumentAdapter(Resource.class, Article.class, Photo.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document, instanceOf(ArrayDocument.class)); ArrayDocument<Resource> arrayDocument = document.asArrayDocument(); assertThat(arrayDocument.get(0), instanceOf(Article.class)); assertThat(arrayDocument.get(1), instanceOf(Photo.class)); assertOnArticle1((Article) arrayDocument.get(0)); }
@Test public void deserialize_multiple_polymorphic_type_priority() throws Exception { Document document = getDocumentAdapter(Resource.class, Photo.Photo2.class, Photo.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo2.class)); Document document2 = getDocumentAdapter(Resource.class, Photo.class, Photo.Photo2.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo2.class)); }
@Test public void deserialize_multiple_polymorphic_type_policy() throws Exception { Document document = getDocumentAdapter(Resource.class, Photo.Photo4.class, Photo.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document.<Resource>asArrayDocument().get(1), instanceOf(Photo.class)); Document document2 = getDocumentAdapter(Resource.class, Photo.Photo4.class, Photo.Photo2.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document2.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo2.class)); Document document3 = getDocumentAdapter(Resource.class, Photo.Photo4.class, Photo.Photo3.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document3.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo3.class)); Document document4 = getDocumentAdapter(Resource.class, Photo.Photo4.class, Photo.Photo5.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document4.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo5.class)); Document document5 = getDocumentAdapter(Resource.class, Photo.class, Photo.Photo4.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document5.<Resource>asArrayDocument().get(1), instanceOf(Photo.class)); Document document6 = getDocumentAdapter(Resource.class, Photo.Photo2.class, Photo.Photo4.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document6.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo2.class)); Document document7 = getDocumentAdapter(Resource.class, Photo.Photo3.class, Photo.Photo4.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document7.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo3.class)); Document document8 = getDocumentAdapter(Resource.class, Photo.Photo5.class, Photo.Photo4.class) .fromJson(TestUtil.fromResource("/multiple_polymorphic.json")); assertThat(document8.<Resource>asArrayDocument().get(1), instanceOf(Photo.Photo5.class)); }
@Test public void deserialize_multiple_resource_identifiers() throws Exception { ArrayDocument document = getDocumentAdapter(ResourceIdentifier.class) .fromJson(TestUtil.fromResource("/relationship_multi.json")).asArrayDocument(); assertThat(document.size(), equalTo(2)); assertThat(document.get(0), instanceOf(ResourceIdentifier.class)); assertThat(document.get(1).getType(), equalTo("tags")); assertThat(getDocumentAdapter(ResourceIdentifier.class) .fromJson(TestUtil.fromResource("/relationship_multi_empty.json")), instanceOf(ArrayDocument.class)); }
@Test public void deserialize_multiple_objects() throws Exception { Document document = getDocumentAdapter(Article.class) .fromJson(TestUtil.fromResource("/multiple_compound.json")); assertThat(document, instanceOf(ArrayDocument.class)); ArrayDocument<Article> arrayDocument = document.asArrayDocument(); assertThat(arrayDocument.size(), equalTo(1)); assertOnArticle1(arrayDocument.get(0)); }