google / google/gson

object graph recursion with polymorphism using GraphAdapterBuilder and RuntimeTypeAdapterFactory

Open
#542 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

```
When used in conjunction, the classes GraphAdapterBuilder and
RuntimeTypeAdapterFactory produce an IllegalStateException "Unexpected
recursive call to read()" on de-serialization.

When used separately, GraphAdapterBuilder can serialize and de-serialize
circular references, and RuntimeTypeAdapterFactory can tackle classes involving
polymorphism. When used together, serialization succeeds but de-serialization
fails.

What steps will reproduce the problem?
Add the attached source files to a project, and execute the JUnit tests.

What is the expected output? What do you see instead?
All tests (testRecursive, testPolymorphic and testPolymorphicRecursive) in the
attached source should pass. Instead, testPolymorphicRecursive fails with an
exception.

What version of the product are you using? On what operating system?
Gson 2.2.4
RuntimeTypeAdapterFactory from
https://code.google.com/p/google-gson/source/browse/trunk/extras/src/main/java/c
om/google/gson/typeadapters/RuntimeTypeAdapterFactory.java
GraphAdapterBuilder from
https://code.google.com/p/google-gson/source/browse/trunk/extras/src/main/java/c
om/google/gson/graph/GraphAdapterBuilder.java with the changes made as
suggested in https://code.google.com/p/google-gson/issues/detail?id=137#c12

```

Original issue reported on code.google.com by `huny...@gmail.com` on 17 Nov 2013 at 2:38

Attachments:
- [gson-polymorphic-recursive.zip](https://storage.googleapis.com/google-code-attachments/google-gson/issue-542/comment-0/gson-polymorphic-recursive.zip)

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.