ok, allora ho modificato usando il metedo più generico:
poi lo richiamo così:codice:public class ReadJson { public <T> T readJson(File file, TypeToken<T> typeToken) throws IOException { Gson gson = new Gson(); try (JsonReader reader = new JsonReader(new FileReader(file))) { T t = gson.fromJson(reader, typeToken.getType()); return t; } } }
funzionare funziona, nel senso che il tutto viene valorizzato e visualizzato in maniera corretta.codice:TypeToken<List<Book>> bookToken = new TypeToken<List<Book>>() {}; List<Book> listBooks = jsonRead.readJson(new File(UrlAndPath.JSON_LIBRI), bookToken);
quindi, se volessi avere un Set piuttosto che una List:
corretto??codice:TypeToken<Set<Book>> bookToken = new TypeToken<Set<Book>>() {}; Set<Book> listBooks = jsonRead.readJson(new File(UrlAndPath.JSON_LIBRI), bookToken);
PS: mi leggerò senz'altro l'articolo che mi hai indicato, spero di capirci abbastanza.

.
Rispondi quotando