ok, allora ho modificato usando il metedo più generico:
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;
}
}
}
poi lo richiamo così:
codice:
TypeToken<List<Book>> bookToken = new TypeToken<List<Book>>() {};
List<Book> listBooks = jsonRead.readJson(new File(UrlAndPath.JSON_LIBRI), bookToken);
funzionare funziona, nel senso che il tutto viene valorizzato e visualizzato in maniera corretta.
quindi, se volessi avere un Set piuttosto che una List:
codice:
TypeToken<Set<Book>> bookToken = new TypeToken<Set<Book>>() {};
Set<Book> listBooks = jsonRead.readJson(new File(UrlAndPath.JSON_LIBRI), bookToken);
corretto??
PS: mi leggerò senz'altro l'articolo che mi hai indicato, spero di capirci abbastanza
.