Retrofit + GSON Deserializer

I have an object like this:

"choice": { "000": { "id": "001", "label": "test", "status": "0" }, "001": { "id": "001", "label": "test", "status": "0" }, "002": { "id": "001", "label": "test", "status": "0" }, "003": { "id": "001", "label": "test", "status": "0" }, "004": { "id": "001", "label": "test", "status": "0" } }, 

How can I parse this object using Gson + Retrofit? Or create a POJO? Is there an easy way to do this?

Many thanks!

+5
source share
3 answers

The basic idea is that all you have in choosing a json object is Map:

 public class RootObject{ Map <String,ChoiceEntry> choice; } public class ChoiceEntry{ String id; String label; int status; } 
+3
source

You can create a POJO by pasting this JSON code in this link: http://pojo.sodhanalibrary.com/ .

You posted a snippet that was not formatted correctly. I believe that you will have a multi-user POJO, and this is difficult to do for certain purposes, such as listviews.

Let me know how this happens. Retrofitting is really nice to use, but extremely annoying to understand!

+2
source

There is an add-on for the intellij / android studio for simple POJO generation.

Disclaimer: I have no connection with the project.

0
source

All Articles