简体   繁体   English

升级到Spring 4.1.6后@JsonIgnore无法正常工作

[英]@JsonIgnore not working after upgrading to spring 4.1.6

I have tried all the solutions provided on SO this and this and many others but nothing seems to solve my problem. 我已经尝试过在SO thisthis以及许多其他解决方案上提供的所有解决方案,但似乎没有什么可以解决我的问题。 I am getting below exception 我在例外之下

com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-

I am not getting why spring using fasterxml.jackson while with previous version it was using it from codehaus 我不明白为什么春天使用fasterxml.jackson而在以前的版本中它是从codehaus使用它的

previous spring version 3.1.2.Release current spring version 4.1.6.Release 先前的春季版本3.1.2发行当前的春季版本4.1.6.Release

You should do quite the opposite to what is recommended in the links you've posted, so change the package of your Jackson classes from org.codehaus.jackson to com.fasterxml.jackson 您应该执行与发布的链接中所建议的相反的操作,因此将Jackson类的包从org.codehaus.jacksoncom.fasterxml.jackson

As of Spring Framework 4.1 , the minimum jackson version should be 2.1 (2.3 recommended) . Spring Framework 4.1开始 ,最低的jackson版本应为2.1 (建议使用2.3) The relevent change, and the suspected cause of your issue is that with jackson 2.x there has been a package shift as well 相关的更改,以及引起问题的可疑原因是,在杰克逊2.x上也发生了包装移位

  • Java package used is "com.fasterxml.jackson" (instead of "org.codehaus.jackson") 使用的Java包是“ com.fasterxml.jackson”(而不是“ org.codehaus.jackson”)
  • Maven group ids begin with"com.fasterxml.jackson" (instead of "org.codehaus.jackson") Maven组ID以“ com.fasterxml.jackson”开头(而不是“ org.codehaus.jackson”)

If you're using maven just replace your current jackson dependencies with this single one 如果您使用的是maven,则只需用此单个替换当前的jackson依赖项

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.1</version>
    </dependency>

Older versions of Spring used Jackson 1.9, which has classes in the org.codehaus.jackson package. Spring的较旧版本使用Jackson 1.9,该版本在org.codehaus.jackson包中包含类。 Spring 4.1.6.Release uses Jackson 2.x, which has its classes in com.fasterxml.jackson package. Spring 4.1.6.Release使用Jackson 2.x,它的类在com.fasterxml.jackson包中。 Therefore old annotations are simply ignored. 因此,旧的注释将被简单地忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM