无法升级到杰克逊2.1.4,泽西岛忽略了注释 [英] Unable to upgrade to Jackson 2.1.4, Jersey ignoring the annotations

查看:112
本文介绍了无法升级到杰克逊2.1.4,泽西岛忽略了注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短版本:

The Short Version:

我使用泽西岛1.17和杰克逊2.1.4,但泽西岛是无视我使用的每一个杰克逊注释。为什么!?有没有人遇到同样的问题?

I am using Jersey 1.17 and Jackson 2.1.4, but Jersey is ignoring every single Jackson-annotation that I use. Why!? Has anybody encountered the same problem?

长版本:

The Long Version:

我有一个使用Jersey 1.17和Jackson 1.9.2的RESTful Web服务,我使用 @JsonManagedReference @JsonBackReference 注释来解决问题双向关系,一切正常。

I have a RESTful Web Service that was using Jersey 1.17 and Jackson 1.9.2 and I was using the @JsonManagedReference and @JsonBackReference annotations to solve the problem with bidirectional relationships and everything was working fine.

前几天,我看到了杰克逊的2.1.4版本,包括 @JsonIdentityInfo 注释对我的问题似乎是一个很好的解决方案所以我将jar文件更改为Jackson 2.1.4。然而,有希望的 @JsonIdentityInfo 注释无效,Jersey完全忽略了它,经过一些调试和更改代码后,我发现即使是之前的 @JsonManagedReference @JsonBackReference 注释被忽略。因此,泽西岛似乎完全无视杰克逊2.1.4注释。为什么!?有没有人遇到同样的问题?

The other day I saw the 2.1.4 version of Jackson that included the @JsonIdentityInfo annotation which seemed like a great solution for my problems so I changed the jar files to Jackson 2.1.4. However, the promising @JsonIdentityInfo annotation was not working and Jersey was ignoring it completely, and after a bit of debugging and changing the code, I found out that even the previous @JsonManagedReference and @JsonBackReference annotations are being ignored by Jersey. So it seems that Jersey is completely ignoring the Jackson 2.1.4 annotations. Why!? Has anybody encountered the same problem?

推荐答案

http://wiki.fasterxml.com/JacksonAnnotations


重要提示:杰克逊1.x和2.x注释存在于不同的Java
和Maven包中:有关完整说明,请参阅Jackson 2.0:

Important note: Jackson 1.x and 2.x annotations live in different Java and Maven packages: see Jackson 2.0 for full explanation:


  • 1 .x注释在Java包中 org.codehaus.jackson.annotate ,在Jackson核心jar中

  • 2.x注释在Java中package com.fasterxml.jackson.annotation ,在jackson-databindjar中。

  • 1.x annotations are in Java package org.codehaus.jackson.annotate, in Jackson core jar
  • 2.x annotations are in Java package com.fasterxml.jackson.annotation, in "jackson-databind" jar.

因此可能是与进口相关的问题。
另一个原因(正如@ HiJon89所说)是使用正确的JacksonJsonProvider版本。对于版本2.x,它会在插入jackson-jaxrs-json-provider和jersey-core时自动注册。

So could be an "import-related" problem. Another reason (as already stated by @HiJon89) is to use the right JacksonJsonProvider version. For version 2.x it's automatically registered while inserting the "jackson-jaxrs-json-provider" combined with "jersey-core".

我目前正在更新jackson 2.1 .4(来自1.9.2球衣需要的依赖)是:

My currently working update to jackson 2.1.4 (from a 1.9.2 jersey required dependency) was:


  • 删除jersey-json依赖

  • 添加jersey-core和jackson-jaxrs-json-provider

  • remove jersey-json dependency
  • add jersey-core and jackson-jaxrs-json-provider

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-json-provider</artifactId>
    <version>${jackson-jaxrs-json-provider.version}</version>
</dependency>


后一个jar有一个文件META- INF / services / javax.ws.rs.ext.MessageBodyWriter告诉球衣什么类充当提供者。

The latter jar has a file "META-INF/services/javax.ws.rs.ext.MessageBodyWriter" that tell jersey what class act as a provider.

所以我没有其他建议而不是加倍检查你的类路径中是否还有旧的罐子。

So I've no other advise than to double-check that you don't have the old jars anymore in your classpath.

这篇关于无法升级到杰克逊2.1.4,泽西岛忽略了注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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