Document implements Serializable { public boolean addInclude(Resource resource) { return getIncluded().add(resource); } 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 serialize_multiple_polymorphic_compound() throws Exception { ArrayDocument document = new ArrayDocument(); Comment comment1 = new Comment(); comment1.setId("1"); comment1.setBody("Awesome!"); Person author = new Person(); author.setId("5"); author.setFirstName("George"); author.setLastName("Orwell"); Article article = new Article(); article.setTitle("Nineteen Eighty-Four"); article.setAuthor(new HasOne<Person>(author)); article.setComments(new HasMany<Comment>(comment1)); document.add(article); document.add(author); document.addInclude(comment1); assertThat(getDocumentAdapter(Resource.class).toJson(document), equalTo("{\"data\":[" + "{\"type\":\"articles\",\"attributes\":{\"title\":\"Nineteen Eighty-Four\"},\"relationships\":{\"author\":{\"data\":{\"type\":\"people\",\"id\":\"5\"}},\"comments\":{\"data\":[{\"type\":\"comments\",\"id\":\"1\"}]}}}," + "{\"type\":\"people\",\"id\":\"5\",\"attributes\":{\"first-name\":\"George\",\"last-name\":\"Orwell\"}}" + "],\"included\":[{\"type\":\"comments\",\"id\":\"1\",\"attributes\":{\"body\":\"Awesome!\"}}]}")); }