I've the following JSON structure:
[
{
"id": 1,
"subcategories": [
{
"id": 2,
"subcategories": [
]
},
{
"id": 3,
"subcategories": [
]
}
]
},
{
"id": 4,
"subcategories": [
{
"id": 5,
subcategories: [
]
}
]
}
]
The model class for a Category (some fields like title are omitted for simplicity), for reflecting JSON structure:
public class Category {
int id = 0;
ArrayList<Category> subCategories = null;
}
I'm trying to parse that with Gson library (2.2.4), having hard times deserializing inner array to arraylist:
Gson gson = new Gson();
Type collectionType = new TypeToken<ArrayList<Category>>(){}.getType();
ArrayList categories = gson.fromJson(json, collectionType);
Category.subCategories is always null.