在泽西使用Gson而不是Jackson [英] Using Gson instead of Jackson in Jersey
本文介绍了在泽西使用Gson而不是Jackson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用JSON对象的RESTful服务,我希望Jersey能够使用Gson而不是Jackson。
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...?
推荐答案
您需要编写自定义的 MessageBodyReader
和 MessageBodyWriter
(可能在同一个类中)并向Jersey注册(如果您使用包扫描, @Provider
注释就足够了) - 非常像 JacksonJsonProvider
: p>
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> { ...
这篇关于在泽西使用Gson而不是Jackson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文