有什么方法可以覆盖或更新 Jersey 的 Jackson 版本吗?

发布于 2024-09-09 00:25:03 字数 744 浏览 12 评论 0原文

我们正在尝试使用 Jackson 1.5 来利用它提供的一些多态处理,但 Jersey 似乎带来了它自己过时的 Jackson 版本 (1.1.1)。在测试 Jersey 序列化 JSON 时,我们得到的结果与在单元测试中手动序列化时得到的结果不同。

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {
      "id": "28",
      "name": "WXYZ",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "W"
  }, {
    "id": "29",
    "field": {
      "id": "29",
      "name": "SEAT",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "4A"
  }]
}

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {}
  }, {
    "id": "29",
    "field": {}
  }],
  "name": null
}

不幸的是,使用 Jackson 1.1.1 不是一个选择。有什么办法让 Jersey 使用 Jackson 1.5 吗?正在考虑尝试将其设置在 Jersey Config 类或其他东西中......

We're trying to use Jackson 1.5 to take advantage of some of the polymorphic handling it offers, but it appears that Jersey brings along it's own outdated version of Jackson (1.1.1). When testing Jersey serialized JSON, we get different results than when we serialize by hand in unit tests.

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {
      "id": "28",
      "name": "WXYZ",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "W"
  }, {
    "id": "29",
    "field": {
      "id": "29",
      "name": "SEAT",
      "strict": "false",
      "valueType": "STRING"
    },
    "value": "4A"
  }]
}

{
  "id": "40",
  "ticketProps": [{
    "id": "28",
    "field": {}
  }, {
    "id": "29",
    "field": {}
  }],
  "name": null
}

Unfortunately using Jackson 1.1.1 is not an option. Is there any way to get Jersey to use Jackson 1.5? Was thinking of trying to set it in the Jersey Config class or something...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我也只是我 2024-09-16 00:25:03

如果 Jersey 的 Maven POM 不允许您将 Jackson 依赖项与 Jersey 依赖项分开,那么您可以手动获取各个 JAR,将 Jackson 1.5.x JAR 替换为 1.1.x JAR。

请注意,不能保证 Jersey 能够与较新的 Jackson 版本配合使用。 Jackson 的 API 在 1.1 版本中发生了很大变化。

If the maven POM for Jersey does not allow you to separate the Jackson dependency from the Jersey dependency, then you could get hold of the individual JARs manually, swapping out the Jackson 1.5.x JAR(s) for the 1.1.x one.

Note that there's no guarantee that Jersey will work with the newer Jackson version. Jackson's API changed quite a lot around the 1.1 releases.

婴鹅 2024-09-16 00:25:03

您没有提供太多详细信息(特别是关于您的运行时环境),因此我将只介绍问题的 Maven 部分:在 dependencyManagement 部分下声明 Jackson 的 1.5 版本,以强制其他版本的收敛以 Jackson 作为依赖项的依赖项。

这是否在运行时有效,留给读者作为练习:)

作为记录,以下是我们可以在 V3.1JerseyOnePager

Jersey 目前在 GlassFish 3.0 中使用 Jackson 1.1。版本将在3.1中升级到最新稳定版本(目前为1.5.2)。

You didn't give much details (especially about your runtime environment) so I'll just cover the maven part of the question: declare the version 1.5 of Jackson under the dependencyManagement section to force the convergence in other dependencies having jackson as dependency.

Wheter this will work at runtime is left as an exercise for the reader :)

For the record, here is what we can read in the V3.1JerseyOnePager:

Jersey is currently using Jackson 1.1 in GlassFish 3.0. The version will be upgraded in 3.1 to the latest stable version (currently 1.5.2).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文