Port YAMLAnchorReplayingFactory from 2.x and improve it to handle nested anchors
#596
+780
−1
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.
Hi,
This PR aims to bring back and fix/improve the
YAMLAnchorReplayingFactoryimplemented in 2.x by @HeikoBoettger-KarlStorz in #502, which was not included in 3.x as the title suggests (cf. #502 (comment)).Although porting this from 2.x to 3.x was not the initial goal of this PR! I originally ran into an issue when using the 2.x version because it wasn't able to handle nested anchors (cf. example at the end). Then I discovered Jackson 3.x was out, and decided to update (because maybe updating fixes issue?). However, I realized that that factory wasn't even in 3.x 😆 So I finally decided to do both at the same time. Nevertheless, I've split it into 2 distinct commits, in case we want to backport that fix to 2.x as well.
I've made sure the author of the original commit was a co-author of this one, to maintain credits for his work (thank him again for that, minor this little nested anchor scenario, it worked well!).
I've added a unit test for nested anchors.
Example of nested anchor YAML document:
Before the fix, the
'text'node event replayed on line 3 by the*valAnchoralias event was not recorded as part of the&objAnchoranchor definition, and thus not replayed at line 4, which caused a parsing failure because of unexpected or illegal sequence of events replayed.Now, events get recorded EVEN if they are part of the replayed events of an alias, when they are in an anchor definition. From my understanding, it should not cause any weird recursion issue, because anchors can only be replayed once they are completely finished to be registered.
Thank you