如何在 JAX-RS 应用程序 (WebSphere Liberty) 中更改 Jackson 版本
How to change Jackson version in JAX-RS app (WebSphere Liberty)
我正在将 JAX-RS 应用程序从 WebSphere 8.0 迁移到 WebSphere Liberty 8.5.5。
在 WebSphere 8.0 中,Jackson 由 WebSphere 提供。我可以在 AppServer\plugins\
目录中找到 jackson-core-asl-1.9.12.jar
、jackson-jaxrs-1.9.12.jar
、jackson-mapper-asl-1.9.12.jar
和 jackson-xc-1.9.12.jar
文件。
在新的应用程序服务器 (WebSphere Liberty) 中,出现以下异常:org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "myPropertyName"
。我认为发生此异常是因为序列化 类 上的注释 @JsonIgnoreProperties(ignoreUnknown = true)
不起作用。我猜这是因为 WebSphere Liberty 8.5.5 提供了旧版本的 Jackson。
我尝试部署我的应用程序所需的 Jackson 版本,
但它没有帮助(我仍然有例外)。如何让 WebSphere Liberty 使用我需要的 Jackson 版本?
Alexey,您是否尝试过对部署在 liberty 上的应用程序使用 parentLast 加载程序方法,以便应用程序 类 可以优先。你可以参考这个question to get more insights. There is documentation for that from IBM as well here
是的,WebSphere Liberty 使用比传统 WAS 更旧的 Jackson 版本。我们需要解决这个问题!
与此同时,您的另一种可能性是使用 jaxrs-2.0 功能,然后在您的应用程序或共享库中包含更新版本的 Jackson。
Liberty 的 jaxrs-1.1 和 jaxrs-2.0 功能之间的区别之一是 jaxrs-2.0 不公开 Jackson API 包。因此应用程序的类加载器将无法加载 Liberty 附带的 Jackson 类。这意味着它将从您的应用程序加载 类 而无需执行 parentLast 委托或其他类加载器技巧。
安迪,希望这对您有所帮助
WebSphere Liberty 将使用您为 JAX-RS 2.0 指定的 Jackson 版本,但有一些注意事项(我们正在努力)。
A) 您仍然必须明确指定 JSON 供应商。
B) 您可能会看到带有 16.0.0.2 的 NPE,如下所述:Regiser JacksonJsonProvider in Websphere liberty profile。我们已经按照描述解决了这个问题。最近的测试版没有表现出这种行为,这表明下一次运行时更新也不会。
和
我们的 gradle 构建引入了 jackson 依赖项:
https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-app/build.gradle
而我们的 server.xml 使用 jaxrs-2.0,但不执行任何类加载器魔术:
https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-wlpcfg/servers/gameon-mediator/server.xml
HTH
我正在将 JAX-RS 应用程序从 WebSphere 8.0 迁移到 WebSphere Liberty 8.5.5。
在 WebSphere 8.0 中,Jackson 由 WebSphere 提供。我可以在 AppServer\plugins\
目录中找到 jackson-core-asl-1.9.12.jar
、jackson-jaxrs-1.9.12.jar
、jackson-mapper-asl-1.9.12.jar
和 jackson-xc-1.9.12.jar
文件。
在新的应用程序服务器 (WebSphere Liberty) 中,出现以下异常:org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "myPropertyName"
。我认为发生此异常是因为序列化 类 上的注释 @JsonIgnoreProperties(ignoreUnknown = true)
不起作用。我猜这是因为 WebSphere Liberty 8.5.5 提供了旧版本的 Jackson。
我尝试部署我的应用程序所需的 Jackson 版本, 但它没有帮助(我仍然有例外)。如何让 WebSphere Liberty 使用我需要的 Jackson 版本?
Alexey,您是否尝试过对部署在 liberty 上的应用程序使用 parentLast 加载程序方法,以便应用程序 类 可以优先。你可以参考这个question to get more insights. There is documentation for that from IBM as well here
是的,WebSphere Liberty 使用比传统 WAS 更旧的 Jackson 版本。我们需要解决这个问题!
与此同时,您的另一种可能性是使用 jaxrs-2.0 功能,然后在您的应用程序或共享库中包含更新版本的 Jackson。
Liberty 的 jaxrs-1.1 和 jaxrs-2.0 功能之间的区别之一是 jaxrs-2.0 不公开 Jackson API 包。因此应用程序的类加载器将无法加载 Liberty 附带的 Jackson 类。这意味着它将从您的应用程序加载 类 而无需执行 parentLast 委托或其他类加载器技巧。
安迪,希望这对您有所帮助
WebSphere Liberty 将使用您为 JAX-RS 2.0 指定的 Jackson 版本,但有一些注意事项(我们正在努力)。
A) 您仍然必须明确指定 JSON 供应商。
B) 您可能会看到带有 16.0.0.2 的 NPE,如下所述:Regiser JacksonJsonProvider in Websphere liberty profile。我们已经按照描述解决了这个问题。最近的测试版没有表现出这种行为,这表明下一次运行时更新也不会。
和
我们的 gradle 构建引入了 jackson 依赖项: https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-app/build.gradle
而我们的 server.xml 使用 jaxrs-2.0,但不执行任何类加载器魔术: https://github.com/gameontext/gameon-mediator/blob/6b469d18965673af35129abf3ff987b61af54c88/mediator-wlpcfg/servers/gameon-mediator/server.xml
HTH