Title: Retrofit list field inside JSON not working
Tags: java;android;arrays;json;retrofit2
Question: I'm using the lastest version of retrofit (2.9.0) to receive data from an API, the data structure (They have the getters and setters):
FamilyResponse.Java
@SerializedName(&quot;codigo&quot;)
@Expose
private String codigo;
@SerializedName(&quot;estado&quot;)
@Expose
private String estado;
@Expose
@SerializedName(&quot;List&quot;)
private List<Family&gt; list;
Family.java
@SerializedName(&quot;idFampr&quot;)
@Expose
private String idFamilia;
@SerializedName(&quot;nomFam&quot;)
@Expose
private String nombre;
MainActivity.java
Call<FamilyResponse&gt; call = ApiClient.getInstance().getApi().getFamiliaProductos(new FamilyRequest(&quot;1&quot;));
call.enqueue(new Callback<FamilyResponse&gt;() {
@Override
public void onResponse(Call<FamilyResponse&gt; call, Response<FamilyResponse&gt; response) {
FamilyResponse familyResponse = response.body();
if(familyResponse!=null)
{
for(Family family:familyResponse.getList()){
Log.d(&quot;Familia&quot;,family.getNombre());
}
}
}
@Override
public void onFailure(Call<FamilyResponse&gt; call, Throwable t) {
}
});
I'm receiving the following:
&quot;codigo&quot;: &quot;1&quot;,
&quot;estado&quot;: &quot;Consulta satisfactoria&quot;,
&quot;list&quot;: [
&quot;idFampr&quot;: 1,
&quot;nomFam&quot;: &quot;Category 1&quot;,
&quot;icoFam&quot;: &quot;img1.jpg&quot;,
&quot;ordFan&quot;: 1
},
&quot;idFampr&quot;: 2,
&quot;nomFam&quot;: &quot;Category 2&quot;,
&quot;icoFam&quot;: &quot;img2.jpg&quot;,
&quot;ordFan&quot;: 2
},
&quot;idFampr&quot;: 3,
&quot;nomFam&quot;: &quot;Category 3&quot;,
&quot;icoFam&quot;: &quot;img3.jpg&quot;,
&quot;ordFan&quot;: 3
},
&quot;idFampr&quot;: 4,
&quot;nomFam&quot;: &quot;Category 4&quot;,
&quot;icoFam&quot;: &quot;img4.jpg&quot;,
&quot;ordFan&quot;: 4
},
&quot;idFampr&quot;: 5,
&quot;nomFam&quot;: &quot;Category 5&quot;,
&quot;icoFam&quot;: &quot;img5.jpg&quot;,
&quot;ordFan&quot;: 5
When i try to read the response.body() for the &quot;List&quot; field is null, but estado and codigo have the correct values

Here is the accepted answer: Please change your @SerializedName(&quot;List&quot;) to @SerializedName(&quot;list&quot;) in FamilyResponse.Java class.
@Expose
@SerializedName(&quot;list&quot;)
private List<Family&gt; list;
For more info, please check documentation
Comment for this answer: Ohh thanks, i cant believe i made an error so dumb. Thank you very much

Here is another answer: Change your @SerializedName(&quot;List&quot;) to @SerializedName(&quot;list&quot;), the name value must be the same as your JSON attribute
NOTE: The value you specify in this annotation must be a valid JSON field name.
Check documentation

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:07/20/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><android><arrays><json><retrofit2>', 'Title': 'Retrofit list field inside JSON not working', 'ViewCount': 49, 'id': 62998645, 'user_AboutMe': '<p>Passionate game developer, hoping to create great games. Marvel / DC comics fan.</p>\n', 'user_AccountId': 11261785.0, 'user_DisplayName': 'LizardStd', 'user_Reputation': 41.0, 'user_Views': 11.0, 'user_id': 8563834.0}}