google / google/gson

Add `JsonDeserializationContext.deserialize` overload with `TypeToken` parameter

Open
#2,216 0 comments 0 reactions 0 assignees View on GitHub
enhancement java8
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

# Problem solved by the feature
Similar to #1700 `JsonDeserializationContext` should have a `deserialize` overload with `TypeToken` parameter to provide type-safety, and the documentation should then recommend that overload.

# Feature description
Since `JsonDeserializationContext` is an interface and might be implemented by users, the `deserialize` overload would have to be implemented as interface `default` method. Therefore this has to wait until Gson targets Java 8 or newer.
The `default` method could then simply delegate to the other overload, though Gson's internal implementation could override it to directly call `Gson.fromJson(..., TypeToken)`.

Maybe it would also be worth considering to deprecate the existing method with `Type` parameter, see also #2328.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.