Skip to content

Commit da1982e

Browse files
committed
Add (failing) tests for #25 and #71
1 parent 78f91fe commit da1982e

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.fasterxml.jackson.dataformat.yaml.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4+
import com.fasterxml.jackson.annotation.JsonSubTypes;
5+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
10+
11+
// [dataformats-text#25]
12+
public class PolymorphicWithObjectId25Test extends ModuleTestBase
13+
{
14+
// [dataformats-text#25]
15+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
16+
include = JsonTypeInfo.As.PROPERTY,
17+
property = "type",
18+
defaultImpl = NodeWithStringId.class)
19+
@JsonSubTypes({
20+
@JsonSubTypes.Type(value = SubNodeWithStringId.class, name= "subnode"),
21+
@JsonSubTypes.Type(value = NodeWithStringId.class, name = "node")
22+
})
23+
@JsonIdentityInfo(generator=ObjectIdGenerators.StringIdGenerator.class)
24+
static class NodeWithStringId
25+
{
26+
public String name;
27+
public String type;
28+
29+
public NodeWithStringId next;
30+
31+
public NodeWithStringId() { }
32+
public NodeWithStringId(String name) {
33+
this.name = name;
34+
}
35+
}
36+
37+
static class SubNodeWithStringId extends NodeWithStringId { }
38+
39+
private final ObjectMapper MAPPER = newObjectMapper();
40+
41+
// [dataformats-text#25]
42+
public void testPolymorphicAndObjectId25() throws Exception
43+
{
44+
String yml = "---\n"
45+
+"&id1 name: \"first\"\n"
46+
+"type: \"node\"\n"
47+
+"next:\n"
48+
+" &id2 name: \"second\"\n"
49+
+" next: *id1"
50+
;
51+
52+
NodeWithStringId node = MAPPER.readValue(yml, NodeWithStringId.class);
53+
54+
assertNotNull(node);
55+
assertEquals("first", node.name);
56+
assertNotNull(node.next);
57+
assertEquals("second", node.next.name);
58+
assertNotNull(node.next.next);
59+
assertSame(node, node.next.next);
60+
}
61+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fasterxml.jackson.dataformat.yaml.failing;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
5+
6+
public class ReadHexInteger71Test extends ModuleTestBase
7+
{
8+
static class IntHolder {
9+
public int value;
10+
}
11+
12+
private final ObjectMapper MAPPER = newObjectMapper();
13+
14+
// [dataformats-text#71]
15+
public void testDeserHexInt71() throws Exception
16+
{
17+
IntHolder result = MAPPER.readerFor(IntHolder.class)
18+
.readValue("value: 0x48");
19+
assertEquals(72, result.value);
20+
}
21+
}

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Tests.java renamed to yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/SimpleGeneration215Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
77
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
88

9-
public class SimpleGeneration215Tests extends ModuleTestBase
9+
public class SimpleGeneration215Test extends ModuleTestBase
1010
{
1111
// [dataformats-text#215]: setting used in constructor
1212
public void testStartMarkerViaWriter() throws Exception

0 commit comments

Comments
 (0)