Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

jaxb - Using Gson instead of Jackson in Jersey

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...?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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> { ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...