I have a RESTful service that consumes and produces JSON objects, and I would like Jersey to use Gson instead of Jackson.
How can this be done...?
You need to write custom implementations of MessageBodyReader
and MessageBodyWriter
(possibly in the same class) and register with Jersey (if you use package scanning, the @Provider
annotation is enough) -- pretty much like JacksonJsonProvider
does it:
@Provider
@Consumes({MediaType.APPLICATION_JSON, "text/json"})
@Produces({MediaType.APPLICATION_JSON, "text/json"})
class GsonJsonProvider implements
MessageBodyReader<Object>,
MessageBodyWriter<Object> { ...