Reputation: 217
I am creating a gym application
Following Entities ClientEntity
TrainerEntity
clientController
trainerController
ClientApi
I have created a bi directional mapping b/w trainer Entity and client entity
When I do findall for client or trainer I an getting nested json as in the Client api and is same with trainer api and is giving JSON: Infinite recursion (StackOverflowError);
Here I want from client api
[
{
"id": 1,
"name": "Bharath",
"address": "#34324 Address",
"trainerEntity": {
"id": 1,
"name": "Niranjan",
}
}
]
trainer api:
[
{
"id": 1,
"name": "Niranjan",
"clientEntity": {
"id": 1,
"name": "Bharath",
"address": "#34324 Address"
}
}
]
Upvotes: 0
Views: 2124
Reputation: 83
You can use @JsonIgnoreProperties , there is a similar question already asked Infinite Recursion with Jackson JSON and Hibernate JPA issue You can use @JsonIgnoreProperties(value ="clientEntity" ) Private TrainerEntity trainerEntity and similarly for the the other side too
A better option is to use Dto's instead of entities to send the response as json.
Upvotes: 1