I've got an entity with the following signature:
public class Record extends BaseEntity {...}
Now I want to send it via REST using JSON. Problem is, the self reference. Because of that I get the following error.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct
self-reference leading to cycle (through reference chain:
Record["this"])
What can I do, e.g. which annotation, to convert this object to JSON?
解决方案
You can use @JsonIgnore annotation in your BaseEntity class above the generic instance variable which is referring to record class. It ignore one of the sides of the relationship, thus breaking the chain.
Alternatively, you can use @JsonManagedReference, @JsonBackReference. You can read more about it here