Skip to content

Commit

Permalink
Fix #63 (requires matching fix in jackson-databind 2.9.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 6, 2019
1 parent e1ad207 commit 191f1a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
<version>2.9.8</version>
<version>2.9.9-SNAPSHOT</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformats-text</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.9.9 (not yet released)

#63: `null` Object Id serialized as anchor for YAML
(reported by jflefebvre06@github)

2.9.8 (15-Dec-2018)

#99: `YamlGenerator` closes the target stream when configured not to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.fasterxml.jackson.dataformat.yaml.failing;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.*;

// for [dataformats-text#63], problem with YAML, Object Ids
public class ObjectId63Test extends ModuleTestBase
{
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public static class SimplePojo {
String id;
String value;

public String getId() {
return this.id;
}

public void setId(final String newId) {
this.id = newId;
}

public String getValue() {
return this.value;
}

public void setValue(final String newValue) {
this.value = newValue;
}
}

private final ObjectMapper MAPPER = newObjectMapper();

public void testIssue63() throws Exception
{
final SimplePojo simplePojoWithId = new SimplePojo();
simplePojoWithId.setId("myId");
simplePojoWithId.setValue("Value");

final SimplePojo simplePojoWithoutId = new SimplePojo();
simplePojoWithoutId.setValue("Value");

assertEquals("---\n&myId id: \"myId\"\nvalue: \"Value\"",
MAPPER.writeValueAsString(simplePojoWithId).trim());

// `null` object id is not to be written as anchor but skipped; property itself
// follows regular inclusion rules.
assertEquals("---\nid: null\nvalue: \"Value\"",
MAPPER.writeValueAsString(simplePojoWithoutId).trim());
}
}

0 comments on commit 191f1a8

Please sign in to comment.