Skip to content

Commit 191f1a8

Browse files
committed
Fix #63 (requires matching fix in jackson-databind 2.9.9)
1 parent e1ad207 commit 191f1a8

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.fasterxml.jackson</groupId>
55
<artifactId>jackson-base</artifactId>
6-
<version>2.9.8</version>
6+
<version>2.9.9-SNAPSHOT</version>
77
</parent>
88
<groupId>com.fasterxml.jackson.dataformat</groupId>
99
<artifactId>jackson-dataformats-text</artifactId>

release-notes/VERSION-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Modules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11+
2.9.9 (not yet released)
12+
13+
#63: `null` Object Id serialized as anchor for YAML
14+
(reported by jflefebvre06@github)
15+
1116
2.9.8 (15-Dec-2018)
1217

1318
#99: `YamlGenerator` closes the target stream when configured not to
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.fasterxml.jackson.dataformat.yaml.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.dataformat.yaml.*;
7+
8+
// for [dataformats-text#63], problem with YAML, Object Ids
9+
public class ObjectId63Test extends ModuleTestBase
10+
{
11+
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
12+
public static class SimplePojo {
13+
String id;
14+
String value;
15+
16+
public String getId() {
17+
return this.id;
18+
}
19+
20+
public void setId(final String newId) {
21+
this.id = newId;
22+
}
23+
24+
public String getValue() {
25+
return this.value;
26+
}
27+
28+
public void setValue(final String newValue) {
29+
this.value = newValue;
30+
}
31+
}
32+
33+
private final ObjectMapper MAPPER = newObjectMapper();
34+
35+
public void testIssue63() throws Exception
36+
{
37+
final SimplePojo simplePojoWithId = new SimplePojo();
38+
simplePojoWithId.setId("myId");
39+
simplePojoWithId.setValue("Value");
40+
41+
final SimplePojo simplePojoWithoutId = new SimplePojo();
42+
simplePojoWithoutId.setValue("Value");
43+
44+
assertEquals("---\n&myId id: \"myId\"\nvalue: \"Value\"",
45+
MAPPER.writeValueAsString(simplePojoWithId).trim());
46+
47+
// `null` object id is not to be written as anchor but skipped; property itself
48+
// follows regular inclusion rules.
49+
assertEquals("---\nid: null\nvalue: \"Value\"",
50+
MAPPER.writeValueAsString(simplePojoWithoutId).trim());
51+
}
52+
}

0 commit comments

Comments
 (0)