Answer the question
In order to leave comments, you need to log in
@JsonIgnoreProperties for ArrayList how to do?
Hello!
There are two entities in my tutorial project: Animal and Client. This is an animal and a master. Each entity has a link to another, that is, Animal has a Client field, and vice versa. Entities are connected Many-to-One, an animal has only one owner, but one owner can have several animals.
The essence of the question is that I have a REST controller, and when I receive some kind of getClientById, I get a recursion where the client refers to the animal, and that, in turn, to the client, and so on in a circle.
I got around this with the @JsonIgnoreProperties annotation. But in the many-to-one case, everything works fine:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id", insertable = false, updatable = false)
@JsonIgnoreProperties("animal")
private Client client;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "client", cascade = CascadeType.ALL)
@JsonIgnoreProperties(value = { "client", "complaints" })
private List<Animal> animals;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question