Skip to content

Commit

Permalink
Add failing tests for #714 (under tofix)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 30, 2025
1 parent fd61dc6 commit c45ea83
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
Expand All @@ -13,7 +14,7 @@ public class XsiNilBasicTest extends XmlTestUtil
{
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";

protected static class DoubleWrapper {
public static class DoubleWrapper {
public Double d;

public DoubleWrapper() { }
Expand All @@ -22,14 +23,17 @@ public DoubleWrapper(Double value) {
}
}

protected static class DoubleWrapper2 {
public static class DoubleWrapper2 {
public Double a = 100.0; // init to ensure it gets overwritten
public Double b = 200.0;

public DoubleWrapper2() { }
}

private final XmlMapper MAPPER = newMapper();
// 30-Jan-2025, tatu: To tease out [dataformat-xml#714] let's do this:
private final XmlMapper MAPPER = mapperBuilder()
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.build();

@Test
public void testWithDoubleAsNull() throws Exception
Expand Down Expand Up @@ -94,6 +98,8 @@ public void testWithDoubleAsMixed() throws Exception
assertEquals(defaultValue.b, bean.b);
}

// [dataformat-xml#714]: trailing END_OBJECT
/*
@Test
public void testRootPojoAsNull() throws Exception
{
Expand All @@ -102,6 +108,7 @@ public void testRootPojoAsNull() throws Exception
Point.class);
assertNull(bean);
}
*/

@Test
public void testRootPojoAsNonNull() throws Exception
Expand Down Expand Up @@ -142,6 +149,8 @@ public void testDisableXsiNilLeafProcessing() throws Exception

// [dataformat-xml#468]: Allow disabling xsi:nil special handling

// [dataformat-xml#714]: trailing END_OBJECT
/*
@Test
public void testDisableXsiNilRootProcessing() throws Exception
{
Expand All @@ -153,10 +162,10 @@ public void testDisableXsiNilRootProcessing() throws Exception
// 07-Jul-2021, tatu: Alas! 2.x sets format feature flags too late to
// affect root element (3.0 works correctly). So cannot test
/*
ObjectReader noXsiNilReader = r.without(FromXmlParser.Feature.PROCESS_XSI_NIL);
assertEquals(a2q("{'nil':'true'}"),
noXsiNilReader.readValue(DOC).toString());
*/
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.fasterxml.jackson.dataformat.xml.tofix;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestUtil;
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
import com.fasterxml.jackson.dataformat.xml.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.*;

public class XsiNilBasic714Test extends XmlTestUtil
{
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";

// 30-Jan-2025, tatu: To tease out [dataformat-xml#714] let's do this:
private final XmlMapper MAPPER = mapperBuilder()
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
.build();

// [dataformat-xml#714]: trailing END_OBJECT
@JacksonTestFailureExpected
@Test
public void testRootPojoAsNull() throws Exception
{
Point bean = MAPPER.readValue(
"<Point "+XSI_NS_DECL+" xsi:nil='true' />",
Point.class);
assertNull(bean);
}

// [dataformat-xml#468]: Allow disabling xsi:nil special handling

// [dataformat-xml#714]: trailing END_OBJECT
@JacksonTestFailureExpected
@Test
public void testDisableXsiNilRootProcessing() throws Exception
{
final ObjectReader r = MAPPER.readerFor(JsonNode.class);
final String DOC = "<Point "+XSI_NS_DECL+" xsi:nil='true'></Point>";

// with default processing:
assertEquals("null", r.readValue(DOC).toString());

// 07-Jul-2021, tatu: Alas! 2.x sets format feature flags too late to
// affect root element (3.0 works correctly). So cannot test

ObjectReader noXsiNilReader = r.without(FromXmlParser.Feature.PROCESS_XSI_NIL);
assertEquals(a2q("{'nil':'true'}"),
noXsiNilReader.readValue(DOC).toString());
}
}

0 comments on commit c45ea83

Please sign in to comment.