When working with Payara I stumble every once in a while over JSON-serialization issues. Payara v4 uses MOXy as default provider while Payara v5 comes with JsonB-support which apparently makes use of Yasson.
Although, after moving from v4 to v5 I’m fine with the JsonB-default it may still be useful to use Jackson as JSON provider instead of the default one (to be honest, many things just worked out-of-the-box with Jackson like reflective access to props (no extra getter necessary) or support for Map
s etc.).
So, there are many useful hints out there where this answer from Ondro Mihályi himself is probably the most useful one. He mentions the getProperties
-method which I perfer to use in my projects instead of the more explicitly shown descriptor-based approaches.
@ApplicationPath("api")
public class BDQVApplication extends javax.ws.rs.core.Application {
@Override
public Map<String, Object> getProperties() {
Map<String, Object> props = new HashMap<>();
props.put("jersey.config.jsonFeature", "JacksonFeature");
return props;
}
...
}
the equivalent can be achieved declaratively i.e. via your web.xml
:
<context-param>
<param-name>jersey.config.jsonFeature</param-name>
<param-value>JacksonFeature</param-value>
</context-param>
This solution works seemlessly in both verisons of Payara - v4 and v5.