Improve settings propagation for temporary JsonTreeReader and JsonTreeWriter#2151
Draft
Marcono1234 wants to merge 5 commits into
Draft
Conversation
…tings Fixes multiple issues where a JsonTreeReader or JsonTreeWriter is used during deserializion / serialization, but the settings from the original JsonReader or JsonWriter (such as lenientness) are not applied.
Contributor
Author
|
Needs additional |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #676
Supersedes #677 (this PR here does not contain the same test code, but have verified that the test code there passed with these changes too)
Description of the issue
In some situations adapters need to:
JsonElement, perform modifications to it and then parse theJsonElementas desired target typeJsonElement, perform modifications to it and then write theJsonElementto the finalJsonWriterIn these situations a temporary
JsonTreeReaderrespectivelyJsonTreeWriteris used. The issue was that these readers and writers were not created with the same settings (lenientness, serialize null) as the original reader or writer. This could cause behavior mismatch or unexpected exceptions during deserialization or serialization.Implementation notes for this PR
This PR introduces two new
TypeAdaptermethods:fromJsonTreeWithSettingsFromandtoJsonTreeWithSettingsFrom. Both apply the settings from an existing reader / writer to the temporaryJsonTreeReader/JsonTreeWriter.This might not be the cleanest solution, so any feedback is appreciated. However, it appears a solution similar to this is necessary because
JsonTreeReaderandJsonTreeWriterare internal classes and therefore cannot be used from outside of Gson (not even from theextrasmodule at the moment), which was the proposed solution in #677.