0

I have this project running in Retrofit with Gson serialized response, but now the API is respond with this kind of array name.0 and this 0 is the index of array, thats mean if the response send 100 items I supposedly create this in code 100 times.

This the response:

{
    "name.0": [
        "Here is the message"
    ],
    "name.1": [
        "Here is the message"
    ],
    "name.2": [
        "Here is the message"
    ],
    ...

}

This is my code for name array:

@SerializedName("name")
@Expose
private List<String> name = null;

I don't want to do this:

@SerializedName("name.0")
@Expose
private List<String> name0 = null;

@SerializedName("name.1")
@Expose
private List<String> name1 = null;

@SerializedName("name.2")
@Expose
private List<String> name2 = null;

...

Thank's in advance.

Daniel Beltrami
  • 756
  • 9
  • 22

1 Answers1

0

While not the prettiest solution, you could make your endpoint call to return a Map<String, List<String>>.

This way you won't have to write all of the possible values of the "name" field and your map will have something like

{name.0=[Here is the message], name.1=[Here is the message], name.2=[Here is the message]}
Fabio
  • 103
  • 1
  • 6