Java to JSON serialization with Jackson PTH and Spring Data MongoDB DBRef generates extra target property

后端 未结 1 1789
独厮守ぢ
独厮守ぢ 2021-01-19 06:46

When serializing from Java to JSON, Jackson generates an extra target property for referenced entities when using the Spring Data MongoDB @DBRef an

相关标签:
1条回答
  • 2021-01-19 07:29

    The Target field is added by Spring Data because it is a lazy collection. So it is like datahandler etc. in Hibernate for JPA.

    Option1: To ignore them you just have to add @JsonIgnoreProperties(value = { "target" }) on class level

    @Document(collection = "song")
    @JsonIgnoreProperties(value = { "target" })
    public class Song {
     ...
    }
    

    Option2: Make the Collection not lazy

    0 讨论(0)
提交回复
热议问题