Creating JSON objects directly from model classes in Java

后端 未结 5 1603
一向
一向 2020-12-17 08:58

I have some model classes like Customer, Product, etc. in my project which have several fields and their setter-getter methods, I need to e

5条回答
  •  不思量自难忘°
    2020-12-17 09:12

    Google GSON does this; I've used it on several projects and it's simple and works well. It can do the translation for simple objects with no intervention, but there's a mechanism for customizing the translation (in both directions,) as well.

    Gson g = ...;
    String jsonString = g.toJson(new Customer());
    

提交回复
热议问题