0

JSON

[
  {
    "id": 1,
    "name": "product new"
  },
  {
    "id": 2,
    "name": "test12345"
  },
  {
    "id": 3,
    "name": "product new"
  }
]

Java

 ArrayList<Product> products
 products = new Gson().fromJson(result.toString(), ArrayList<Product>.getClass());

how can I convert the JSON array to Product class based ArrayList?

1 Answers1

1

Try this :

import com.google.gson.reflect.TypeToken;

ArrayList<Product> products  = new Gson().fromJson(results, new TypeToken<ArrayList<Product>>(){}.getType());;
Mouad EL Fakir
  • 3,609
  • 2
  • 23
  • 37