Using the Gson library, how do I convert a JSON string to an ArrayList
of a custom class JsonLog
? Basically, JsonLog
is an interface implemented by different kinds of logs made by my Android app--SMS logs, call logs, data logs--and this ArrayList
is a collection of all of them. I keep getting an error in line 6.
public static void log(File destination, JsonLog log) {
Collection<JsonLog> logs = null;
if (destination.exists()) {
Gson gson = new Gson();
BufferedReader br = new BufferedReader(new FileReader(destination));
logs = gson.fromJson(br, ArrayList<JsonLog>.class); // line 6
// logs.add(log);
// serialize "logs" again
}
}
It seems the compiler doesn't understand I'm referring to a typed ArrayList
. What do I do?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…