Skip to content

Commit

Permalink
Mention in User Guide alternative for Gson versions without fromJson(…
Browse files Browse the repository at this point in the history
…..., TypeToken) (#2209)
  • Loading branch information
Marcono1234 committed Sep 30, 2022
1 parent 9c9cafc commit ea7ab7c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions UserGuide.md
Expand Up @@ -226,6 +226,8 @@ String json = gson.toJson(ints); // ==> json is [1,2,3,4,5]

// Deserialization
TypeToken<Collection<Integer>> collectionType = new TypeToken<Collection<Integer>>(){};
// 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<Integer> ints2 = gson.fromJson(json, collectionType);
// ==> ints2 is same as ints
```
Expand Down Expand Up @@ -267,6 +269,8 @@ TypeToken<Map<String, String>> mapType = new TypeToken<Map<String, String>>(){};
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<String, String> stringMap = gson.fromJson(json, mapType);
// ==> stringMap is {key=value}
```
Expand Down

0 comments on commit ea7ab7c

Please sign in to comment.