Need immutable instances of JsonObject and JsonArray
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
```
The framework I write requires immutable JsonArray and JsonObject types to
avoid having to constantly make deep copies. Luckily Gson is extensible enough
that I can build these myself, by extending JsonElement. The only hiccup is
that that the code in JsonTreeReader and JsonTreeWriter uses 'instanceof' to
determine how to parse and serialize json, which makes creation of new
JsonElement types impossible.
With a few small polymorphic code changes I was able to get these new immutable
JsonElements to behave just like the normal ones. I have not benchmarked any
performance impacts, but if the performance impacts are minimal, I think this
would be an excellent feature and would allow users to build new element types.
Attached is the patch of changes I applied to the internal framework, along
with the immutable IJsonObject and IJsonArray that I created for reference and
testing.
```
Original issue reported on code.google.com by `alan.gar...@gmail.com` on 23 Aug 2012 at 4:50
Attachments:
- [PolymorphicParserPatch.diff](https://storage.googleapis.com/google-code-attachments/google-gson/issue-467/comment-0/PolymorphicParserPatch.diff)
- [IJsonArray.java](https://storage.googleapis.com/google-code-attachments/google-gson/issue-467/comment-0/IJsonArray.java)
- [IJsonObject.java](https://storage.googleapis.com/google-code-attachments/google-gson/issue-467/comment-0/IJsonObject.java)
Contributor guide
Assessment
This issue has not been assessed yet.