Skip to content

Commit 399c327

Browse files
committed
Add test for (now fixed) #231
1 parent 997837e commit 399c327

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Modules:
2020
#226: (yaml) Quote 'y'/'Y'/'n'/'N' as names too (to avoid problems with Boolean keys)
2121
(requested by pnepywoda@github)
2222
#229: (yaml) Allow configuring the way "must quote" is determined for property names, String values
23+
#231: Typed object with anchor throws Already had POJO for id (note: actual
24+
fix in `jackson-annotations`)
25+
(reported by almson@github)
2326
- Add configurability of "YAML version generator is to follow" via "YAMLFactory.builder()"
2427
- SnakeYAML 1.26 -> 1.27
2528
- Add Gradle Module Metadata (https://blog.gradle.org/alignment-with-gradle-module-metadata)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.fasterxml.jackson.dataformat.yaml.misc;
2+
3+
import java.util.List;
4+
5+
import com.fasterxml.jackson.annotation.*;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.dataformat.yaml.*;
9+
10+
public class ObjectAndTypeId231Test extends ModuleTestBase
11+
{
12+
static class Container {
13+
@JsonProperty
14+
public List<Base> list;
15+
}
16+
17+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
18+
@JsonSubTypes({@JsonSubTypes.Type(name="Derived", value=Derived.class)})
19+
@JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class)
20+
static class Base {
21+
22+
}
23+
24+
static class Derived extends Base {
25+
@JsonProperty
26+
String a;
27+
}
28+
29+
private final ObjectMapper MAPPER = newObjectMapper();
30+
31+
// [dataformats-text#231]
32+
public void testTypeAndObjectId231() throws Exception
33+
{
34+
String yaml = "list:\n" +
35+
" - !Derived &id1\n" +
36+
" a: foo";
37+
Container container = MAPPER.readValue (yaml, Container.class);
38+
assertNotNull(container);
39+
assertNotNull(container.list);
40+
assertEquals(1, container.list.size());
41+
42+
System.out.println (((Derived)container.list.get(0)).a);
43+
}
44+
}

0 commit comments

Comments
 (0)