Regiser JacksonJsonProvider in Websphere liberty profile
Asked Answered
H

0

6

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.

Herrenvolk answered 18/7, 2016 at 22:0 Comment(3)
I suspect it is a bug. The latest beta driver does not exhibit this behavior (I've raised it and we're chasing). FWIW, we just hit it with one of our apps, too.Ithunn
The most recent beta driver seems not to have this issue for our application. True for you as well?Ithunn
@ebullient, thanks for the note. I will give it a try and let you know. However could you please tell what driver did you mean?Herrenvolk

© 2022 - 2024 — McMap. All rights reserved.