I have the following entity:
@Entity
@Table(name = \"registry_entry\")
@JsonIgnoreProperties(ignoreUnknown = true)
public class RegistryEntry extends GenericEnti
Jackson supports @JsonIdentityInfo. This is does what you're describing: adding this annotation to a class will make all instances of that class be serialized with an additional ID field, and the next time the same instance needs to be serialized the value of that ID field will be written instead of the whole object.
However, note that this is not standard JSON. In general, JSON format is usually used because it's widely supported by many libraries. Using this feature will likely create additional problems for your API clients.
The more universally compatible approach is to serialize the self-referenced object without its self-reference field:
public class RegistryEntry {
@JsonIgnoreProperties("relatedRegistryEntries")
private List relatedRegistryEntries;
}