How to use Jackson 2 in Payara 5?

耗尽温柔 提交于 2019-12-05 02:42:29

问题


I'm using Jackson 2 with Payara 4 and I would liked to use Jackson 2 in Payara 5.

Using JAX-RS, I also would like to avoid changing annotations and so on...

In Payara 5 the default Jsonb provider is Yasson. Any ideas to disable it and use Jackson instead? All comments/ideas are welcome :-)

NB: Yasson is very interesting but handle abstract class or interface serialization/deserialization is a little more complex than putting a Jackson annotation. My current understanding is that it requires to implement a JsonbSerializer/Deserializer but actually the serializer/deserializer is only available on field/method (an issue is opened for class, which will be very helpful). Anyway, migrating to Yasson will mean implementing many serializer/deserializer as required (for entities and of course collections) but I guess it's a hard stuff.


回答1:


You need to set the property jersey.config.jsonFeature to JacksonFeature so that the default JsonB feature isn't registered.

You can set it either in the code by overriding the Application.getProperties() method, or set the property in web.xml as context-param:

<context-param>
  <param-name>jersey.config.jsonFeature</param-name>
  <param-value>JacksonFeature</param-value>
</context-param>

You also need to add Jackson dependencies into your application - but you have probably done that already so ignore this.

Explanation:

The MOXy feature provides a property jersey.config.disableMoxyJson to disable it. The JsonB feature default in Payara 5 doesn't provide such property but will not register itself if jersey.config.jsonFeature property exists and is not JsonBindingFeature. The same property works for all Jersey features so setting it to JacksonFeature will allow only the JacksonFeature to be registered.



来源:https://stackoverflow.com/questions/49793289/how-to-use-jackson-2-in-payara-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!