Search code examples
androiddictionarygsonretrofitpojo

Retrofit + GSON deserializer


I have an object like this one:

"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 that object with Gson+Retrofit? Or generate a POJO? There is an easy way of doing this?

Many thanks!


Solution

  • The main idea that all that you have in choice json object is Map:

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