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

Replay buffered parser to create different (reference) objects at alias #1046

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Polar-Pumpkin
Copy link

@Polar-Pumpkin Polar-Pumpkin commented Feb 28, 2025

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! ❤️

Use IYamlConvertible to flatten collection with anchor
Use buffered parser to replay ParsingEvents in order to re-create different reference object when unfold AnchorAlias (but in order to accept self-cycling anchor, cached object will used when detected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant