Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ public JsonGenerator overrideFormatFeatures(int values, int mask)
/**********************************************************
*/

@Override
public StreamWriteConstraints streamWriteConstraints() {
return _ioContext.streamWriteConstraints();
}

public ToXmlGenerator enable(Feature f) {
_formatFeatures |= f.getMask();
return this;
Expand Down Expand Up @@ -536,6 +541,7 @@ public final void writeStartArray() throws IOException
{
_verifyValueWrite("start an array");
_writeContext = _writeContext.createChildArrayContext();
streamWriteConstraints().validateNestingDepth(_writeContext.getNestingDepth());
if (_cfgPrettyPrinter != null) {
_cfgPrettyPrinter.writeStartArray(this);
} else {
Expand All @@ -562,6 +568,7 @@ public final void writeStartObject() throws IOException
{
_verifyValueWrite("start an object");
_writeContext = _writeContext.createChildObjectContext();
streamWriteConstraints().validateNestingDepth(_writeContext.getNestingDepth());
if (_cfgPrettyPrinter != null) {
_cfgPrettyPrinter.writeStartObject(this);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fasterxml.jackson.dataformat.xml.ser.dos;

import com.fasterxml.jackson.core.StreamWriteConstraints;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

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 XmlTestBase
{
private final XmlMapper MAPPER = newMapper();

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));
}
}
}