Skip to content

Commit 2270031

Browse files
committed
Merge branch '3.0' into 3.x
2 parents 6f80c1e + b566fb1 commit 2270031

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

yaml/src/test/java/tools/jackson/dataformat/yaml/tofix/ObjectIdNone296Test.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,34 @@
88
import tools.jackson.databind.ObjectMapper;
99
import tools.jackson.dataformat.yaml.ModuleTestBase;
1010
import tools.jackson.dataformat.yaml.testutil.failure.JacksonTestFailureExpected;
11+
import tools.jackson.dataformat.yaml.YAMLMapper;
1112

1213
import static org.junit.jupiter.api.Assertions.assertEquals;
1314
import static org.junit.jupiter.api.Assertions.assertNotNull;
1415
import static org.junit.jupiter.api.Assertions.assertSame;
1516

16-
// [dataformats-text#296]: YAML Anchor and alias fails with ObjectIdGenerators.None
17+
/**
18+
* [dataformats-text#296]: YAML Anchor and alias with ObjectIdGenerators.None
19+
*<p>
20+
* NOTE: ObjectIdGenerators.None with YAML anchors/aliases currently does NOT work
21+
* as expected due to a limitation in Jackson's databind layer.
22+
*<p>
23+
* While the parser correctly exposes object IDs via getObjectId(), Jackson's
24+
* object ID resolution doesn't properly cache and reuse objects when using
25+
* ObjectIdGenerators.None, even with YAMLAnchorReplayingFactory.
26+
*<p>
27+
* WORKAROUND: Users should use ObjectIdGenerators.StringIdGenerator (or other
28+
* generators) instead of ObjectIdGenerators.None for YAML anchor/alias support.
29+
*/
1730
public class ObjectIdNone296Test extends ModuleTestBase
1831
{
19-
private final ObjectMapper MAPPER = newObjectMapper();
32+
// YAMLAnchorReplayingFactory properly replays anchored events, but
33+
// ObjectIdGenerators.None still doesn't work for de-duplication
34+
//
35+
// 01-Nov-2025, tatu: Alas, [dataformats-text#502] only applied to 2.x (2.20)
36+
// so NOT available on 3.x
37+
// private final ObjectMapper MAPPER = YAMLMapper.builder(new YAMLAnchorReplayingFactory()).build();
38+
private final ObjectMapper MAPPER = YAMLMapper.builder().build();
2039

2140
@JacksonTestFailureExpected
2241
@Test
@@ -28,10 +47,6 @@ public void testObjectIdUsingNativeAnchorsWithNoneGenerator() throws Exception
2847
" value: bar\n" +
2948
"boo: *foo1\n";
3049

31-
// This should work: YAML anchors/aliases should be recognized natively
32-
// when using ObjectIdGenerators.None, but currently fails with:
33-
// "Cannot construct instance of StringHolder... no String-argument
34-
// constructor/factory method to deserialize from String value ('foo1')"
3550
ScratchModel result = MAPPER.readValue(YAML_CONTENT, ScratchModel.class);
3651

3752
assertNotNull(result);
@@ -40,6 +55,7 @@ public void testObjectIdUsingNativeAnchorsWithNoneGenerator() throws Exception
4055
assertNotNull(result.boo);
4156
assertEquals("bar", result.boo.value);
4257
// The key assertion: both fields should point to the same object instance
58+
// Currently FAILS - creates two separate instances with same content
4359
assertSame(result.foo, result.boo);
4460
}
4561

@@ -54,7 +70,7 @@ static class StringHolder {
5470
public String value;
5571

5672
protected StringHolder() { }
57-
73+
5874
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
5975
public StringHolder(String v) { value = v; }
6076

0 commit comments

Comments
 (0)