how to expose class names when serializing with Gson

后端 未结 3 1028
夕颜
夕颜 2021-01-26 02:44

My scenario is very complicated but here\'s a summary:

I\'m trying to understand source of a compiler -- and to understand what each AST node represents, I\'m generating

3条回答
  •  旧巷少年郎
    2021-01-26 03:23

    You can also use Genson to add class name of your objects to the outputed json, just do:

    Genson genson = new Genson.Builder().setWithClassMetadata(true).create();
    String json = genson.serialize(yourNode);
    

    The nice thing is that it enables you to deserialize back to those concrete types. See the wiki for more details.

提交回复
热议问题