YamlDotNet
YamlDotNet copied to clipboard
Replay buffered parser to create different (reference) objects at alias
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! ❤️