Jackson confused with bidirectional one-to-many relationship

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

    As a first solution, I kept these annotations and created an other class: ContactWithouPhoneNumber and added it as a field to the PhoneNumber class.

    Now, before rendering, I copy all fields except PhoneNumber, from contact to contactWithoutPhoneNumber. The output JSON contains every thing I need.

    This is the DTO design pattern.

提交回复
热议问题