英文:
Serialize POJO to JSON through a provider
问题
什么是一种常见的自动方式将Java Beans 序列化为 JSON?@Produces(MediaType.APPLICATION_JSON)
似乎在底层不处理转换。我们是要创建自己的 JSON 提供程序,还是有其他方法?目前,我正在尝试通过 ContextResolver 处理它:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/ContextResolver.html
我理解 @Produces
注解应该在资源类方法之一返回Java对象时帮助创建预期的输出。
英文:
What is a common way to serialize Java Beans to JSON in a automatic fashion? The @Produces(MediaType.APPLICATION_JSON)
doesnt seem to handle the conversion under the hood. Do we create our own JSON Providers or is there another way? Currently im trying to handle it via the ContextResolver:
https://docs.oracle.com/javaee/7/api/javax/ws/rs/ext/ContextResolver.html
It is my understanding that the @Produces
annotation should help create the expected output if a java object is returned from one of the resource class methods.
答案1
得分: 0
你不必自己编写基于Jackson的提供程序。
在Apache Karaf中,您可以简单地安装特性 aries-jax-rs-whiteboard-jackson。
如果您不使用Karaf,可以自行安装来自特性的捆绑项:
英文:
You do not have to code the jackson based provider yourself.
In apache karaf you can simply install the feature aries-jax-rs-whiteboard-jackson.
If you are not using karaf you can install the bundles from the feature yourself:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论