Class:
public class MyList {
public int type;
public String text;
public boolean[] arr;
public MyList(int type, String text) {
this.type = type;
this.text = text;
switch (type) {
case 0:
arr = new boolean[5];
break;
case 1:
arr = new boolean[10];
break;
}
}
}
JSON Data:
{ "list": [ { "type": 0, "text": "Text 1" }, { "type": 1, "question": "Text 2" } ] }
Parser:
ArrayList<MyList> getList(){
Gson gson = new Gson();
MyListsArray mLists = gson.fromJson(bufferString, MyListsArray.class);
return mLists.list;
}
Class to hold the list items:
public class MyListsArray {
public ArrayList<MyList> list;
}
Everything goes fine, I get proper values for type and text which are present in the JSON String. But the arr remains null.