Replay buffered parser to create different (reference) objects at alias #1046
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.
In response to the issues mentioned in #1043 and #1045, I have written two corresponding unit tests. The solution is to cache the buffered parsers in a way similar to
ITypeDiscriminatingNodeDeserializer
, and then replay the buffer when unfolding aliases to recreate objects with different reference addresses.While running the unit tests, I noticed that YAML allows self-referencing anchors to create cycles. Therefore, I added a check that uses the original cached-object-based solution when a self-reference is detected.
After the fix, the unit test
RoundtripArrayOfIdenticalObjects
failed because the objects were serialized as anchors, representing the same references. However, during deserialization, different references were generated (although the content was the same), causing the test to fail. This left me unsure whether what I did was correct: do anchors only represent objects with the same reference?That being said, I just wanted to use anchors to simplify the parts of my configuration file that require duplication. If you're open to my understanding of anchors, I could also implement this as an switch in builder.
Thank you very much for any support and help you provide! ❤️