Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (de-)serialization support for Iterable #1709

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented May 25, 2020

This adds only support for (de-)serializing Iterable, but not any of its subtypes since it would not be possible to properly deserialize them again (see also #1708 and #1389).

The targeted use case is classes with Iterable fields:

class CustomIterable extends Iterable<Integer> {
  public Iterator<Integer> iterator() {
    ...
  }
}

class MyClass {
  Iterable<Integer> iterable;
}

public static void main(String... args) {
  MyClass obj = new MyClass();
  obj.iterable = new CustomIterable();
  gson.toJson(obj); // = {"iterable":[...]}
}

However, since it only supports Iterable (and no subtypes) it might not be useful enough. It would be good to gather some feedback on how useful it would be and which use cases it would suit.

Note that these changes might have an effect for serialization of fields with compile-time type Iterable for which previously the reflective adapter for the runtime type was used (see how TypeAdapterRuntimeTypeWrapper chooses the type adapter).

This adds only support for (de-)serializing Iterable, but not any of its
subtypes since it would not be possible to properly deserialize them again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants