Could not write JSON: Infinite recursion (StackOverflowError); nested exception spring boot

前端 未结 7 1393
时光说笑
时光说笑 2020-12-08 23:18

This is my District Controller, when I try to fetch data after saving I get the error, even when I try get object form getDistrict(Long id) the same strikes ple

7条回答
  •  遥遥无期
    2020-12-08 23:49

    Looks like your problem is Hibernate relations. When you try to serialize the entity Statemaster the serializer calls serialization of the Districtmaster set which in turn somehow reference the Statemaster again.

    There are two possible ways to solve:

    1. Unproxy object
    2. Create DTO (Data Transfer Object) - kind of copy of your entity where all necessary fields should be assigned and return the DTO.

提交回复
热议问题