I'm new in Android programming's world and I've some problems using JSON to serialize and deserialize an ArrayList of custom objects. I know how to serialize an object, but not if it has an ArrayList as a field.
I found the GSON library but I don't really know how to use it.
I have an ArrayList of a class A which has an ArrayList of a class B. I'm serializing class A using a toJSON() method:
public class A
{
//Some fields like title, id...
private String mTitle;
private ArrayList<B> mArray; //I don't know how to serialize/deserialize this field
public A(){...}
public A(JSONObject json){...}
public JSONObject toJSON() throws JSONException //method I use to convert my object into a JSONObject
{
JSONObject json = new JSONObject();
json.put("TITLE",mTitle);
return json;
}
}
public class B
{
//some fields like a double, String...
public B(){...}
}