-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
police against issues with writing cyclic data (#421)
- Loading branch information
Showing
13 changed files
with
176 additions
and
3 deletions.
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
32 changes: 32 additions & 0 deletions
32
csv/src/test/java/com/fasterxml/jackson/dataformat/csv/ser/dos/CyclicDataSerTest.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,32 @@ | ||
package com.fasterxml.jackson.dataformat.csv.ser.dos; | ||
|
||
import com.fasterxml.jackson.core.StreamWriteConstraints; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.dataformat.csv.CsvMapper; | ||
import com.fasterxml.jackson.dataformat.csv.ModuleTestBase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Simple unit tests to verify that we fail gracefully if you attempt to serialize | ||
* data that is cyclic (eg a list that contains itself). | ||
*/ | ||
public class CyclicDataSerTest extends ModuleTestBase | ||
{ | ||
private final CsvMapper MAPPER = mapperForCsv(); | ||
|
||
public void testListWithSelfReference() throws Exception { | ||
List<Object> list = new ArrayList<>(); | ||
list.add(list); | ||
try { | ||
MAPPER.writeValueAsString(list); | ||
fail("expected JsonMappingException"); | ||
} catch (JsonMappingException jmex) { | ||
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", | ||
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); | ||
assertTrue("JsonMappingException message is as expected?", | ||
jmex.getMessage().startsWith(exceptionPrefix)); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...erties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/dos/CyclicDataSerTest.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,32 @@ | ||
package com.fasterxml.jackson.dataformat.javaprop.dos; | ||
|
||
import com.fasterxml.jackson.core.StreamWriteConstraints; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper; | ||
import com.fasterxml.jackson.dataformat.javaprop.ModuleTestBase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Simple unit tests to verify that we fail gracefully if you attempt to serialize | ||
* data that is cyclic (eg a list that contains itself). | ||
*/ | ||
public class CyclicDataSerTest extends ModuleTestBase | ||
{ | ||
private final JavaPropsMapper MAPPER = newPropertiesMapper(); | ||
|
||
public void testListWithSelfReference() throws Exception { | ||
List<Object> list = new ArrayList<>(); | ||
list.add(list); | ||
try { | ||
MAPPER.writeValueAsString(list); | ||
fail("expected JsonMappingException"); | ||
} catch (JsonMappingException jmex) { | ||
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", | ||
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); | ||
assertTrue("JsonMappingException message is as expected?", | ||
jmex.getMessage().startsWith(exceptionPrefix)); | ||
} | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
toml/src/test/java/com/fasterxml/jackson/dataformat/toml/dos/CyclicDataSerTest.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,37 @@ | ||
package com.fasterxml.jackson.dataformat.toml.dos; | ||
|
||
import com.fasterxml.jackson.core.StreamWriteConstraints; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.toml.TomlMapperTestBase; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* Simple unit tests to verify that we fail gracefully if you attempt to serialize | ||
* data that is cyclic (eg a list that contains itself). | ||
*/ | ||
public class CyclicDataSerTest extends TomlMapperTestBase | ||
{ | ||
private final ObjectMapper MAPPER = newTomlMapper(); | ||
|
||
@Test | ||
public void testListWithSelfReference() throws Exception { | ||
List<Object> list = new ArrayList<>(); | ||
list.add(list); | ||
try { | ||
MAPPER.writeValueAsString(list); | ||
fail("expected JsonMappingException"); | ||
} catch (JsonMappingException jmex) { | ||
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", | ||
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); | ||
assertTrue("JsonMappingException message is as expected?", | ||
jmex.getMessage().startsWith(exceptionPrefix)); | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/dos/CyclicDataSerTest.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,33 @@ | ||
package com.fasterxml.jackson.dataformat.yaml.ser.dos; | ||
|
||
import com.fasterxml.jackson.core.StreamWriteConstraints; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Simple unit tests to verify that we fail gracefully if you attempt to serialize | ||
* data that is cyclic (eg a list that contains itself). | ||
*/ | ||
public class CyclicDataSerTest extends ModuleTestBase | ||
{ | ||
private final ObjectMapper MAPPER = YAMLMapper.builder().build(); | ||
|
||
public void testListWithSelfReference() throws Exception { | ||
List<Object> list = new ArrayList<>(); | ||
list.add(list); | ||
try { | ||
MAPPER.writeValueAsString(list); | ||
fail("expected JsonMappingException"); | ||
} catch (JsonMappingException jmex) { | ||
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed", | ||
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1); | ||
assertTrue("JsonMappingException message is as expected?", | ||
jmex.getMessage().startsWith(exceptionPrefix)); | ||
} | ||
} | ||
} |