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:
MessageBodyReader
MessageBodyWriter
@Provider
JacksonJsonProvider
@Provider @Consumes({MediaType.APPLICATION_JSON, "text/json"}) @Produces({MediaType.APPLICATION_JSON, "text/json"}) class GsonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { ...
2.1m questions
2.1m answers
60 comments
57.0k users