Итак, у меня возникли проблемы с десериализацией некоторого JSON, у которого вложенные ArrayLists, корневой элемент десериализуется нормально, но внутри него вложенный массив ArrayList (Called mTest) имеет нулевое значение. Сначала это действительный JSON.Deserializing объекты с вложенными ArrayLists с Gson?
[
{
"mRecipeName": "FirstRecipe",
"mTest": [
{
"mIngredientName": "TestIngredient1",
"mIngredientAmount": "1",
"mUnit": "tbsp"
},
{
"mIngredientName": "TestIngredient2",
"mIngredientAmount": "2",
"mUnit": "tbsp"
}
],
"mRecipeDescription": "Recipe1"
},
{
"mRecipeName": "SecondRecipe",
"mTest": [
{
"mIngredientName": "TestIngredient1",
"mIngredientAmount": "1",
"mUnit": "tbsp"
},
{
"mIngredientName": "TestIngredient2",
"mIngredientAmount": "2",
"mUnit": "tbsp"
}
],
"mRecipeDescription": "Recipe2"
}
]
Вот рецепт класса
public class Recipe {
public String mRecipeName; //This values good
public String mRecipeDescription; //This values good
public ArrayList<Test> mTest; //This returns null
}
Вот тест Класс
public class Test {
public String mIngredientName;
public float mIngredientAmount;
public String mUnit;
}
А вот как я называю это
//Is there another way to do this? Or does this have to be done for every nested
//ArrayList? If so how?
Gson gson = new Gson();
ArrayList<Recipe> result = gson.fromJson(json, new TypeToken<ArrayList<Recipe>>() {}.getType());
Спасибо очень заблаговременно до тех, кто отвечает!