I've got an internet request that send to my App a list of JSON object (the request work correctly, i've already tried it). When i try to save all the json to a List of same Object as the JSON, it get all null and i dont know how to fix that.
Here's the for
that save in the List
:
public void getCards(MasterJsonCard mjc){
downloadedCardList = new ArrayList<>();
for(Master card : mjc.getMaster())
downloadedCardList.add(new Master(card.getId(),card.getExpansion(),card.getImgpath(),card.getLitness(),card.getName(),card.getDankness(),card.getRarity(),card.getValue()));
// THIS ONLY GET ALL NULL
new addCartRealms().execute(); //EXECUTING A THREAD FOR SOME REASON
}
This is where i get data:
public void downloadCard(){
if(!isOnline()) //Controllo se è presente la connessione
Toast.makeText(mainMenu.this, "Connessione Assente", Toast.LENGTH_LONG).show();
else {
String news_url = "HERE_THE_URL";
String index_string = String.valueOf(totalRealmCardNumber);
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder()
.add("index", index_string)
.build();
Request request = new Request.Builder()
.url(news_url)
.post(formBody)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
downloadCardResponse = response.body().string();
handler.post(new Runnable() {
@Override
public void run() {
Gson gson = new Gson();
MasterJsonCard mjc = gson.fromJson(downloadCardResponse, MasterJsonCard.class);
getCards(mjc);
}
});
}
});
}
This is result seen in the debugger:
MasterJsonCard:
public class MasterJsonCard
{
private Master[] master;
public Master[] getMaster ()
{
return master;
}
public void setMaster (Master[] master)
{
this.master = master;
}
@Override
public String toString()
{
return "ClassPojo [master = "+master+"]";
}
}
Master:
public class Master
{
private String id;
private String expansion;
private String imgpath;
private String litness;
private String name;
private String dankness;
private String rarity;
private String value;
public Master(String id, String expansion, String imgpath, String litness, String name, String dankness, String rarity, String value) {
}
public String getId ()
{
return id;
}
public void setId (String id)
{
this.id = id;
}
public String getExpansion ()
{
return expansion;
}
public void setExpansion (String expansion)
{
this.expansion = expansion;
}
public String getImgpath ()
{
return imgpath;
}
public void setImgpath (String imgpath)
{
this.imgpath = imgpath;
}
public String getLitness ()
{
return litness;
}
public void setLitness (String litness)
{
this.litness = litness;
}
public String getName ()
{
return name;
}
public void setName (String name)
{
this.name = name;
}
public String getDankness ()
{
return dankness;
}
public void setDankness (String dankness)
{
this.dankness = dankness;
}
public String getRarity ()
{
return rarity;
}
public void setRarity (String rarity)
{
this.rarity = rarity;
}
public String getValue ()
{
return value;
}
public void setValue (String value)
{
this.value = value;
}
@Override
public String toString()
{
return "ClassPojo [id = "+id+", expansion = "+expansion+", imgpath = "+imgpath+", litness = "+litness+", name = "+name+", dankness = "+dankness+", rarity = "+rarity+", value = "+value+"]";
}
}