Skip to content
Advertisement

How to return a ManyToOne Bidirectional JPA Entity Object in response of a Spring RestController?

I have 2 entities User and Authority having bidirectional Many-To-One relationship b/w them. But when I send the User object as a response from the RestController, I get nested objects ie. User{Authority{User{Authority{User{Authority{..}}}}}}

How can I achieve that the controller must return only? User{Authority{}}

Below is my User entity class :-

JavaScript
JavaScript
JavaScript

Below is the snippet from my browser: enter image description here

JavaScript

Advertisement

Answer

in Authorities class add @JsonIgnore above the User field

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement