users@jersey.java.net

[Jersey] MessageBodyWriter error when using AsyncResponse.resume()

From: Paul O'Fallon <paul_at_ofallonfamily.com>
Date: Tue, 8 Apr 2014 09:02:08 -0400

Hello. I'm creating a sample RESTful API for a course I'm developing and
I'm running into an error while trying to use the async functionality of
Jersey 2. I'm using Jersey 2.7 and the Grizzly 2 HTTP container (starting
with a project originally generated by the Maven archetype).

This synchronous code works and correctly returns a JSON array of book data:

@GET
@Produces(MediaType.APPLICATION_JSON)
public Collection<Book> getBooks() {
    return(dao.getBooks());
}

(The "getBooks" method in the DAO class returns the values() of a
ConcurrentHashMap of Books.)

Rewriting this to use async, however, generates an error:

@GET
@Produces(MediaType.APPLICATION_JSON)
@ManagedAsync
public void getBooks(@Suspended AsyncResponse response) {
    response.resume(dao.getBooks());
}

The error is:

Apr 07, 2014 8:50:28 PM
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor
aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json,
type=class java.util.concurrent.ConcurrentHashMap$Values, genericType=class
java.util.concurrent.ConcurrentHashMap$Values.

However, if I edit my POM and comment out the "jersey-media-moxy"
dependency, add "jackson-jaxrs-json-provider" (v2.3.0), and register a new
JacksonJsonProvider() in my ResourceConfig, the above async code works.

So it appears the sync version of the code works with moxy, but the async
code does not. Yet the async code works with Jackson. (FWIW, I'm not
doing any special MessageBodyReader/Writer configuration in either case --
just using the defaults wherever possible).

Any insight as to why this doesn't work with moxy is greatly appreciated.
 Thank you!

- Paul