update RawCollectionsExample.java (#1953)

use static method instead deprecated method
This commit is contained in:
Z 2021-09-07 23:02:04 +08:00 committed by GitHub
parent 9484297fbb
commit ebe4b581dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,8 +45,7 @@ public class RawCollectionsExample {
collection.add(new Event("GREETINGS", "guest"));
String json = gson.toJson(collection);
System.out.println("Using Gson.toJson() on a raw collection: " + json);
JsonParser parser = new JsonParser();
JsonArray array = parser.parse(json).getAsJsonArray();
JsonArray array = JsonParser.parseString(json).getAsJsonArray();
String message = gson.fromJson(array.get(0), String.class);
int number = gson.fromJson(array.get(1), int.class);
Event event = gson.fromJson(array.get(2), Event.class);