Skip to content

Commit

Permalink
Fix typo in UserGuide (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
prempalsingh authored and inder123 committed Sep 18, 2019
1 parent 3958b1f commit 0409a2e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ gson.toJson(foo); // May not serialize foo.value correctly
gson.fromJson(json, foo.getClass()); // Fails to deserialize foo.value as Bar
```

The above code fails to interpret value as type Bar because Gson invokes `list.getClass()` to get its class information, but this method returns a raw class, `Foo.class`. This means that Gson has no way of knowing that this is an object of type `Foo<Bar>`, and not just plain `Foo`.
The above code fails to interpret value as type Bar because Gson invokes `foo.getClass()` to get its class information, but this method returns a raw class, `Foo.class`. This means that Gson has no way of knowing that this is an object of type `Foo<Bar>`, and not just plain `Foo`.

You can solve this problem by specifying the correct parameterized type for your generic type. You can do this by using the [`TypeToken`](https://static.javadoc.io/com.google.code.gson/gson/2.8.5/com/google/gson/reflect/TypeToken.html) class.

Expand Down

0 comments on commit 0409a2e

Please sign in to comment.