在泽西岛从 1.9 升级到 Jackson 2.0 不起作用 [英] Upgrading to Jackson 2.0 from 1.9 in Jersey not working

查看:24
本文介绍了在泽西岛从 1.9 升级到 Jackson 2.0 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jackson(在泽西岛)序列化实体,并且我正在从 Jackson 1.9 迁移到 2.0.我遵循了本指南,起初似乎一切正常轻松出门.

I'm using Jackson (in Jersey) to serialize entities, and I'm migrating from Jackson 1.9 to 2.0. I followed this guide, and at first it seemed like everything worked out easily.

但仔细观察会发现 Jackson 1.9 仍在用于序列化我的回复,因此忽略了我的(迁移的)Jackson 2.0 注释.您可以在以下代码片段中看到我使用了哪些注解:

But a closer look reveals that Jackson 1.9 is still being used to serialize my responses, and therefore ignoring my (migrated) Jackson 2.0 annotation. You can see which annotations I'm using in the following code fragment:

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public abstract class IdEntity {

@Id
@JsonDeserialize(using = ObjectIdJsonDeserializer.class)
protected ObjectId id;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonSerialize(using = ObjectIdJsonSerializer.class)
public ObjectId getId() {
    return id;
}

public void setId(ObjectId id) {
    this.id = id;
}

@JsonIgnore
public String getIdAsString() {
    return id == null ? "" : id.toString();
}

我的 @JsonIgnore getter 正在序列化,而我的 ObjectIdJsonSerializer 没有用于 ObjectId 字段.

My @JsonIgnore getters are getting serialized, and my ObjectIdJsonSerializer isn't being used for the ObjectId field.

在调试中我可以看到正在使用的 ObjectMapper 来自 1.9.

In debug I can see that the ObjectMapper being used is from 1.9.

我已经删除了对 Jackson 1.9 的所有直接 maven 依赖项,并尝试向 jersey-json 添加排除项,以防止它引入 Jackson 1.9.但是我不能完全摆脱它(通过在我的依赖管理中排除所有 codehaus.jackson 的东西),因为我也在使用 Spring AMQP,它需要 Jackson 1.9.

I've removed all the direct maven dependencies to Jackson 1.9, and tried adding exclusions to jersey-json, to prevent it from pulling in Jackson 1.9. But I can't get rid of it entirely (by putting an exclusion to all the codehaus.jackson stuff in my dependency management) because I'm also using Spring AMQP, which needs Jackson 1.9.

关于如何管理此问题的任何想法?有没有人遇到/解决过类似的问题?如何强制 Jersey 使用 Jackson 2.0?

Any ideas on how to manage this? Has anyone encountered / solved a similar problem? How do I force Jersey to use Jackson 2.0?

推荐答案

我正在根据 StaxMan 和 pgelinas 的(有用的)答案回答我自己的问题.

I'm answering my own question, based on the (useful) answers from StaxMan and pgelinas.

我必须做两件事才能让它发挥作用.

I had to do two things to make it work.

第一件事是从我的 web.xml 中删除 com.sun.jersey.api.json.POJOMappingFeature.

The first things was to remove the com.sun.jersey.api.json.POJOMappingFeature from my web.xml.

第二个是将我的 jackson-jaxrs-json-provider(实际上是我所有的 Jackson 工件)更新到 2.1.

The second was to update my jackson-jaxrs-json-provider (actually, all of my Jackson artifacts) to 2.1.

对于 2.1 或 2.0 以及 POJOMappingFeature,Jackson 1.9 仍用于序列化.

With 2.1 or 2.0, and POJOMappingFeature, Jackson 1.9 was still being used for serialization.

使用 2.0 并删除 POJOMappingFeature,我收到了缺少消息正文编写器的错误.

With 2.0, and POJOMappingFeature removed, I got a missing message body writer error.

删除 2.1 和 POJOMappingFeature 后,一切正常.

With 2.1 and POJOMappingFeature removed, everything worked as expected.

这篇关于在泽西岛从 1.9 升级到 Jackson 2.0 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆