diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2019-10-23 12:25:59 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2019-10-23 12:25:59 -0700 |
commit | d3983fe7e9334033a80ebd7d7f298f6c8f1bd9fb (patch) | |
tree | d2c00922efeaf83392f98db39dbea2c61f25b2d1 /src/test/java/com/fasterxml/jackson/databind/ser | |
parent | 1222a7c263efa0c7b80c719fef2105c86c83f922 (diff) | |
download | jackson-databind-d3983fe7e9334033a80ebd7d7f298f6c8f1bd9fb.tar.gz |
Move #2501 test to better place
Diffstat (limited to 'src/test/java/com/fasterxml/jackson/databind/ser')
-rw-r--r-- | src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java b/src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java index d6cdf2756..644779644 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/ser/CyclicTypeSerTest.java @@ -2,7 +2,6 @@ package com.fasterxml.jackson.databind.ser; import java.util.*; - import com.fasterxml.jackson.databind.*; /** @@ -30,6 +29,14 @@ public class CyclicTypeSerTest public void assignNext(Bean n) { _next = n; } } + static class Selfie2501 { + public int id; + + public Selfie2501 parent; + + public Selfie2501(int id) { this.id = id; } + } + /* /********************************************************** /* Types @@ -38,7 +45,7 @@ public class CyclicTypeSerTest private final ObjectMapper MAPPER = newJsonMapper(); - public void testLinked() throws Exception + public void testLinkedButNotCyclic() throws Exception { Bean last = new Bean(null, "last"); Bean first = new Bean(last, "first"); @@ -55,10 +62,7 @@ public class CyclicTypeSerTest assertNull(map2.get("next")); } - /** - * Test for verifying that [JACKSON-158] works as expected - */ - public void testSelfReference() throws Exception + public void testSimpleDirectSelfReference() throws Exception { Bean selfRef = new Bean(null, "self-refs"); Bean first = new Bean(selfRef, "first"); @@ -70,4 +74,19 @@ public class CyclicTypeSerTest verifyException(e, "Direct self-reference leading to cycle"); } } + + // [databind#2501]: Should be possible to replace null cyclic ref + public void testReplacedCycle() throws Exception + { + Selfie2501 self1 = new Selfie2501(1); + self1.parent = self1; + + ObjectWriter w = MAPPER.writer() + .without(SerializationFeature.FAIL_ON_SELF_REFERENCES) + .with(SerializationFeature.WRITE_SELF_REFERENCES_AS_NULL) + ; + final String json = w.writeValueAsString(self1); + assertNotNull(json); + assertEquals(aposToQuotes("{'id':1,'parent':null}"), json); + } } |