Jackson serialize problem in @ManyToMany relationship

前端 未结 1 1216
终归单人心
终归单人心 2020-12-07 03:53

I have the following situation:

//--class user --
private ....

@OneToMany(targetEntity = UserRoles.class, mappedBy = \"iduser\", fetch = FetchType.LAZY)
@Js         


        
相关标签:
1条回答
  • 2020-12-07 04:52

    For both classes you should have defined some ID property, we can use to identify objects in data base. We can use it to help Jackson to identify instances in runtime. You can remove @JsonBackReference and @JsonManagedReference and instead use com.fasterxml.jackson.annotation.JsonIdentityInfo annotation:

    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
            property = "iduser")
    class User {
    ...
    }
    

    and

    @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
            property = "idgruppo")
    class Gruppi {
    ...
    }
    
    0 讨论(0)
提交回复
热议问题