How to use Jackson as JSON provider for JAX-RS-Client instead of Johnzon in TomEE 7?

被刻印的时光 ゝ 提交于 2019-12-05 17:01:47
Romain Manni-Bucau

Johnzon is registered on the bus by default to have a default JSON (mapping) and JSON-P provider. CXF is clever enough to make bus providers with a lower priority than applications ones (register() for client API) so if you call register you expect to use jackson...and still use johnzon - I suspect it is the case you hit.

That's perfectly normal and due to two things:

  1. JAX-RS specification priority definition
  2. Jackson Consumes/Produce definition

To summarize (1) says that more specific is the provider higher is its priority so an "application/json" provider will be priveledged in favor of a "/" one.

To avoid issues Johnzon uses "application/json". However jackson uses a custom matching strategy and therefore uses "/". So the bus priority is ignored since mediatype priority is enough to say johnzon is "more adapted" than jackson for json.

To solve it the easiest is likely to override jackson provider (just extend it) and decorate it with @Provides/@Consumes with MediaType.APPLICATION_JSON instead of wildcard one.

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