You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the same object appears multiple times in the serialized graph, the default behaviour is to emit it only once, assigning it an anchor, and use aliases to reference it on its subsequent occurrences. DisableAliases prevents this and causes the object to be emitted multiple times.
What does "same object" mean? Going by the current implementation, it's "equal by value", but judging by how anchors and aliases are supposed to help with circular references (at least from what I understand), I'd rather take it to mean "equal by reference". This is causing a bit of a headache for us right now as objects are being "merged" when round-tripping, most easily seen with records. Should two equal records exist which do not refer to the same object, both now do after deserialization. And we'd want to disable that merging behavior without risking reused references causing problems.
After digging in the code it doesn't do anything special to the objects it uses as a key in the underlying dictionary. So, with that, it would use what the dictionary uses which I believe is Equals and GetHashCode to compare the objects and not by reference.
Hopefully that helps.
If you need more help on the internals of YamlDotNet, I'm here to help, reopen the issue with any additional comments.
Apologies in advance if this question is misplaced here.
@WEGFan found a possible problem in how we're using YamlDotNet in a project of ours, and it's unclear if it's a problem to begin with, or if I'm misunderstanding the docs.
According to the documentation:
What does "same object" mean? Going by the current implementation, it's "equal by value", but judging by how anchors and aliases are supposed to help with circular references (at least from what I understand), I'd rather take it to mean "equal by reference". This is causing a bit of a headache for us right now as objects are being "merged" when round-tripping, most easily seen with
record
s. Should two equalrecord
s exist which do not refer to the same object, both now do after deserialization. And we'd want to disable that merging behavior without risking reused references causing problems.@WEGFan found that the
AnchorAssigner
is using a dictionary under the hood. Should it be using an equality comparer that usesReferenceEquals
? Or is the default behavior checkingEquals
andGetHashCode
intended for aliases?The text was updated successfully, but these errors were encountered: