I found some strange behaviour that I cannot understand.
I have tested 4 similar examples:
1
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response produce() {
List<Book> books = Arrays
.asList(new Book[] {
new Book("aaa", "AAA", "12345"),
new Book("bbb", "BBB", "09876")
});
return Response.ok(books).build();
}
2
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Book> produce() {
List<Book> books = Arrays
.asList(new Book[] {
new Book("aaa", "AAA", "12345"),
new Book("bbb", "BBB", "09876")
});
return books;
}
3
@GET
@Produces(MediaType.APPLICATION_XML)
public List<Book> produce() {
List<Book> books = Arrays
.asList(new Book[] {
new Book("aaa", "AAA", "12345"),
new Book("bbb", "BBB", "09876")
});
return books;
}
4
@GET
@Produces(MediaType.APPLICATION_XML)
public Response produce() {
List<Book> books = Arrays
.asList(new Book[] {
new Book("aaa", "AAA", "12345"),
new Book("bbb", "BBB", "09876")
});
return Response.ok(books).build();
}
Everything works in #1, #2, #3 but 4th example throws:
Could not find MessageBodyWriter for response object of type: java.util.Arrays$ArrayList of media type: application/xml.
I run it on Wildfly 9 and I wonder if it is related to RestEasy or JaxRS in general? I know that I can fix it by wrapping collection in GenericEntity, but I don't understand this inconsistent behaviour.