Jackson confused with bidirectional one-to-many relationship

前端 未结 4 2114
天命终不由人
天命终不由人 2020-12-14 22:53

I\'m using jackson 1.9.2 with Hibernate/Spring MVC through MappingJacksonHttpMessageConverter.

Jackson can not serialize bidirectional one-to-many relationship and

4条回答
  •  醉话见心
    2020-12-14 23:14

    I recently encountered a similar problem: Jackson - serialization of entities with birectional relationships (avoiding cycles)

    So the solution is to upgrade to Jackson 2.0, and add to classes the following annotation:

    @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, 
                      property = "@id")
    public class SomeEntityClass ...
    

    Then the problem is that Spring doesn't work with Jackson 2.0. This has been solved in the following way:

    
    
    
            
                
                    
                
            
            
        
    

    And the own.implementation.of.MappingJacksonHttpMessageConverter is based on this:

    http://www.jarvana.com/jarvana/view/org/springframework/spring-web/3.0.0.RELEASE/spring-web-3.0.0.RELEASE-sources.jar!/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java?format=ok

    But use ObjectMapper and other Jackson classes from Jackson 2.0 instead of Jackson 1.*

提交回复
热议问题