Is there a solution about Gson “circular reference”?

后端 未结 3 1360
囚心锁ツ
囚心锁ツ 2020-12-19 00:05

I have found many articles about the circular reference with Gson, but I can\'t find an elegant solution.

As I know, some solutions is:

  • Set the propert
3条回答
  •  囚心锁ツ
    2020-12-19 00:46

    I am looking into this issue as well. Gson does not provide a default solution so far. What you can do is:

    Option 1: Create an exclusion strategy which implements ExclusionStrategy to exclude the class and/or field in the circular reference;

    Option 2: Use annotations to mark the field to be transient to avoid serialization;

    Option 3: Create your own type adapter

提交回复
热议问题