-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1ad207
commit 191f1a8
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/failing/ObjectId63Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |