Jackson confused with bidirectional one-to-many relationship

前端 未结 4 2115
天命终不由人
天命终不由人 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:27

    One thing wrong in your class def is use of untyped List; you should rather have:

    List phoneNumber ;
    

    since otherwise Jackson can not know what the type is when deserializing; and even on serializing it could cause problems (as base type is not known for sure). So I would first fix this issue.

    But additionally your dependency may be wrong way around: @JsonManagedReference MUST always be the first thing to serialize. If this is not the case, you can not use these annotations. Without seeing objects you are trying to serialize it is hard to know for sure (POJO definition and JSON seem slightly off).

提交回复
热议问题