0

I'm using Gson to parse json to my object :

@SerializedName("MyAttribute")
    private List<MyObject> myObject;

But in one call the answer for the same attribute could be different. In one hand :

"MyAttribute":[  
      "stringInformation",
      "stringInformation2"
   ]

It's a list of String, In the other hand it's a list of object :

"MyAttribute":[  
          {  
            "id":"info",
            "info":"info",
            "info2":"info
          },
          {  
            "id":"info",
            "info":"info",
            "info2":"info
          }
       ]

For mapping the object it's ok, my Gson is set to parse this into the list of my object. But I would like to create a list of these object if it's only a list of Strgin in my json file. Do you have an idea how to deal with it ? Thank you

Romain Caron
  • 257
  • 1
  • 3
  • 15
  • I think you can easily apply my answer for this [this question](https://stackoverflow.com/q/52456821/6413377) but it is of course only one alternative. – pirho Oct 25 '18 at 19:22

1 Answers1

-1

You must create 2 different objects for responses:

@SerializedName("MyAttribute")
private List<Strings> myStrings;


@SerializedName("MyAttribute")
private List<MyObject> myObject;