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

查看:146
本文介绍了从泽西岛的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.

I已经删除了所有直接的maven依赖关系到Jackson 1.9,并尝试在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.

关于如何管理这个的任何想法?有没有人遇到/解决了类似的问题?我如何强迫泽西岛使用杰克逊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 (实际上,我所有的杰克逊文物)到 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天全站免登陆