How do I use Google's Gson API to deserialize JSON properly?

后端 未结 2 528
旧巷少年郎
旧巷少年郎 2020-11-27 05:07

In short, this is a sketch of the JSON object I want to parse in JAVA:

{
    object1: {
            item1: //[String | Array | Object] ,
            item2: /         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 06:03

    I think BalusC gave good pointers for the specific question wrt GSon (and in general, one-to-one data binding); but just in case you think there should be more dynamic handling, you could also consider other JSON processing packages. Many packages have additional or alternative ways to map things: Json-lib, flexjson and Jackson at least have additions compared to Gson. Some offer looser mapping (you define names of things to types), others actual support for polymporphic types (declaring an Object but can actually map to subtype that was serialized).

提交回复
热议问题