ciao andbin!
sto provando seguendo il tuo consiglio.
ho modificato la classe Book:
poi ho modificato così:codice:public class Book { private String id; private String title; private String author; private String editor; private String price; private String isbn; private String note; // GETTER E SETTER }
però ottengo questo errore:codice:public class ReadJson { private final Gson gson; public ReadJson() { gson = new Gson(); } public <T> List<T> readJson(File file, Class<T> type) throws IOException { TypeToken<List<T>> listTypeToken = new TypeToken<List<T>>(){}; JsonReader reader = new JsonReader(new FileReader(file)); List<T> list = gson.fromJson(reader, listTypeToken.getType()); /*ArrayList<T> list = new ArrayList<>(); JsonParser parser = new JsonParser(); try (BufferedReader bf = new BufferedReader(new FileReader(file))) { JsonArray jarray = parser.parse(new JsonReader(bf)).getAsJsonArray(); for (JsonElement e : jarray) { T element = gson.fromJson(e, type); list.add(element); } }*/ return list; } }
ma ad essere sincero non ho ben capito...codice:Caused by: java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.mp.book.Book

Rispondi quotando