diff --git a/pom.xml b/pom.xml index 8cfabaa1..89fcf725 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.fasterxml.jackson jackson-base - 2.9.8 + 2.9.9-SNAPSHOT com.fasterxml.jackson.dataformat jackson-dataformats-text diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index bc29fb98..86957721 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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 diff --git a/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectId63Test.java b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectId63Test.java new file mode 100644 index 00000000..afaf13b6 --- /dev/null +++ b/yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectId63Test.java @@ -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()); + } +}