From ea7ab7cd520199fdb4a8d47fe462a4a0357a58bb Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Fri, 30 Sep 2022 16:57:02 +0200 Subject: [PATCH] Mention in User Guide alternative for Gson versions without fromJson(..., TypeToken) (#2209) --- UserGuide.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UserGuide.md b/UserGuide.md index 2aafb067..49ac54d4 100644 --- a/UserGuide.md +++ b/UserGuide.md @@ -226,6 +226,8 @@ String json = gson.toJson(ints); // ==> json is [1,2,3,4,5] // Deserialization TypeToken> collectionType = new TypeToken>(){}; +// Note: For older Gson versions it is necessary to use `collectionType.getType()` as argument below, +// this is however not type-safe and care must be taken to specify the correct type for the local variable Collection ints2 = gson.fromJson(json, collectionType); // ==> ints2 is same as ints ``` @@ -267,6 +269,8 @@ TypeToken> mapType = new TypeToken>(){}; String json = "{\"key\": \"value\"}"; // Deserialization +// Note: For older Gson versions it is necessary to use `mapType.getType()` as argument below, +// this is however not type-safe and care must be taken to specify the correct type for the local variable Map stringMap = gson.fromJson(json, mapType); // ==> stringMap is {key=value} ```