Skip to content

Conversation

@indyteo
Copy link

@indyteo indyteo commented Dec 11, 2025

Hi,

This PR aims to bring back and fix/improve the YAMLAnchorReplayingFactory implemented 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:

value: &valAnchor 'text'
obj1: &objAnchor
  string: *valAnchor
obj2: *objAnchor

Before the fix, the 'text' node event replayed on line 3 by the *valAnchor alias event was not recorded as part of the &objAnchor anchor 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

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

yaml Issue related to YAML format backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants