How to generate GSONFormat for a property that can either be an object or string?

梦想与她 提交于 2019-12-25 04:12:15

问题


I'm using GSON for parsing response from a Volley request and got stuck in creating a GSON format when the response has a property that can either be a string or an object or an array perhaps... e.g content

{
      "data": {
        "date_updated": "2016-12-21T03:55:29.955Z",
        "date_created": "2016-12-21T03:55:29.955Z",
        "content": "String here",
        "content": {
            "longitude": "",
            "latitude": ""
        },
        "status": "PROC",
        "_id": "5859fd31a93c7235575d62db"
      }
}

My current process in creating a GSON model is:

  1. Create a java class
  2. Right click and select Generate > GSONFormat
  3. Paste the object I'm trying to convert then use it in Volley. I tried the above object but it doesn't proceed. I think it's because of same property name.

Thanks for your advice.


回答1:


You can use GsonFormat, you can look this: https://github.com/zzz40500/GsonFormat



来源:https://stackoverflow.com/questions/41255196/how-to-generate-gsonformat-for-a-property-that-can-either-be-an-object-or-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!