google / google/gson

Built-in support for Guava collections

Open
#2,742 3 comments 0 reactions 1 assignee Claimed by @eamonnmcmanus View on GitHub
enhancement Priority-Medium Type-Enhancement
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

# Problem solved by the feature
Although Gson and Guava are both Google open-source projects, Gson does not have any understanding of Guava collection-related types such as `ImmutableList` and `ImmutableSortedMap`. There is [at least one open-source project](https://github.com/acebaggins/guava-gson-serializers) that provides this functionality, but it does not currently seem to be released anywhere accessible. Internally, Google seems to have at least 12 implementations of `ImmutableListTypeAdapterFactory`.

# Feature description
Make it so that a default `Gson` instance knows how to deserialize into `ImmutableList` and the like, _if_ Guava is on the classpath. We can use reflection and an `` dependency to ensure that Gson does not pull in Guava if it is not already used elsewhere in a project.

# Alternatives / workarounds
Build [`guava-gson-serializers`](https://github.com/acebaggins/guava-gson-serializers) manually, or write your own `TypeAdapterFactory`.

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.