I am trying to call a REST service from an EJB hoping to utilize Jackson's
@JsonIgnoreProperties(ignoreUnknown = true)
The following does the trick in wlp v8.5.5.9
Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class);
The same code produces a NullPointerException
in the wlp v16.0.0.2
Caused by: java.lang.NullPointerException
at org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders.getContextResolver(ThreadLocalProviders.java:50)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.locateMapper(JacksonJsonProvider.java:634)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:413)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:438)
... 98 more
I have found a discussions triggered by the same problems in v8.5.5.9, but I am not sure how it could help me. As I noted I have no troubles with the code in the v8.5.5.9
Another discussion was related to the Jackson v2.x. Initially I used Jackson v1.9.13, but I have tried to switch to the newest Jeckson 2.8.0 version and apply the offered solution. The same outcome: application works in wlp 8.5.5.9 and produces the same error in v16.0.0.2.
Any ideas?
Update: the problem could be avoided by extending the JacksonJsonProvider class and explicitly providing object mapper
public class MyJacksonJsonProvider extends JacksonJsonProvider {
public MyJacksonJsonProvider() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibilityChecker(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
setMapper(objectMapper);
}
}
and then registering it in the client
Client client = ClientBuilder.newClient().register(MyJacksonJsonProvider.class);
However it would be nice to understand if it is a bug or a feature.