Document implements Serializable { public boolean setErrors(Collection<Error> errors) { this.errors.clear(); if (errors != null) { this.errors.addAll(errors); } return true; } 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_errors() throws Exception { Error error = new Error(); error.setId("4"); error.setStatus("502"); error.setTitle("Internal error"); error.setCode("502000"); error.setDetail("Ouch! There's some trouble with our server."); ObjectDocument document = new ObjectDocument(); document.setErrors(Collections.singletonList(error)); assertThat(getDocumentAdapter(null).toJson(document), equalTo("{\"error\":[{\"id\":\"4\",\"status\":\"502\",\"code\":\"502000\",\"title\":\"Internal error\",\"detail\":\"Ouch! There's some trouble with our server.\"}]}")); }