Search code examples
jakarta-eejacksonjax-rswebspherewebsphere-liberty

How to change Jackson version in JAX-RS app (WebSphere Liberty)


I am migrating a JAX-RS application from WebSphere 8.0 to WebSphere Liberty 8.5.5.

In WebSphere 8.0, Jackson was provided by WebSphere. I can find jackson-core-asl-1.9.12.jar, jackson-jaxrs-1.9.12.jar, jackson-mapper-asl-1.9.12.jar and jackson-xc-1.9.12.jar files in the AppServer\plugins\ directory.

In the new application server (WebSphere Liberty), I get the following exception: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "myPropertyName". I think that this exception happens because the annotation @JsonIgnoreProperties(ignoreUnknown = true) on the serialized classes does not work. My guess is that it happens because WebSphere Liberty 8.5.5 provides an older version of Jackson.

I tried to deploy the version of Jackson which I need with my application, but it did not help (I still have exceptions). How can I make WebSphere Liberty use the version of Jackson that I need?


Solution

  • WebSphere Liberty will use the version of Jackson you specify with JAX-RS 2.0, with a few caveats (which we are chasing).

    A) You still have to specify JSON providers explicitly.

    B) You may see an NPE with 16.0.0.2 as described here: Regiser JacksonJsonProvider in Websphere liberty profile. We've worked around that as described. The most recent beta doesn't exhibit this behavior, which suggests the next runtime update won't either.

    Examples: https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-app/src/main/java/org/gameontext/mediator/JaxbJsonProvider.java

    and

    https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-app/src/main/java/org/gameontext/mediator/JsonProvider.java

    Our gradle build brings in the jackson dependency: https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-app/build.gradle

    And our server.xml uses jaxrs-2.0, but doesn't do any classloader magic: https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-wlpcfg/servers/gameon-mediator/server.xml

    HTH