Regiser JacksonJsonProvider on Websphere Freedom Profile

I am trying to call a REST service from EJB, hoping to use Jackson

@JsonIgnoreProperties(ignoreUnknown = true) 

Below is the trick in wlp v8.5.5.9

 Client client = ClientBuilder.newClient().register(JacksonJsonProvider.class); 

The same code throws a NullPointerException in 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 found discussions caused by the same problems in version 8.5.5.9, but I'm not sure how this could help me. As I said, I have no problem with the code in v8.5.5.9.

Another discussion was related to Jackson v2.x. I originally used Jackson v1.9.13, but I tried to upgrade to the new version of Jeckson 2.8.0 and apply the proposed solution. Same result: the application runs in wlp 8.5.5.9 and generates the same error in v16.0.0.2.

Any ideas?

Update: the problem could be avoided by extending the JacksonJsonProvider class and explicitly providing the mapper object

 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 register it in the client

 Client client = ClientBuilder.newClient().register(MyJacksonJsonProvider.class); 

However, it would be nice to see if this is a bug or function.

+5
source share

All Articles