获取:无法写入 JSON:无限递归(StackOverflowError);嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException
我正在创建一个健身房应用程序
以下实体 ClientEntity
TrainerEntity
clientController
trainerController
ClientApi
我创建了一个双向映射黑白训练器实体和客户端实体
当我为客户端或训练器执行 findall 时,我得到了与客户端 api 中一样的嵌套 json,并且与训练器 api 相同并给出 JSON: 无限递归 (StackOverflowError);
在这里我想要从 客户端 api
[
{
"id": 1,
"name": "Bharath",
"address": "#34324 Address",
"trainerEntity": {
"id": 1,
"name": "Niranjan",
}
}
]
训练器 api:
[
{
"id": 1,
"name": "Niranjan",
"clientEntity": {
"id": 1,
"name": "Bharath",
"address": "#34324 Address"
}
}
]
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"
}
}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 @JsonIgnoreProperties ,已经提出了类似的问题 Infinite Jackson JSON 和 Hibernate JPA 问题的递归
您可以使用
@JsonIgnoreProperties(值=“clientEntity”)
私人教练Entity trainerEntity
另一方也类似。
更好的选择是使用 Dto 而不是实体来将响应作为 json 发送。
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.