有什么方法可以覆盖或更新 Jersey 的 Jackson 版本吗?
我们正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 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.
您没有提供太多详细信息(特别是关于您的运行时环境),因此我将只介绍问题的 Maven 部分:在
dependencyManagement
部分下声明 Jackson 的 1.5 版本,以强制其他版本的收敛以 Jackson 作为依赖项的依赖项。这是否在运行时有效,留给读者作为练习:)
作为记录,以下是我们可以在 V3.1JerseyOnePager:
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: