-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing tests for #714 (under
tofix
)
- Loading branch information
1 parent
fd61dc6
commit c45ea83
Showing
2 changed files
with
69 additions
and
5 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
55 changes: 55 additions & 0 deletions
55
src/test/java/com/fasterxml/jackson/dataformat/xml/tofix/XsiNilBasic714Test.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,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()); | ||
} | ||
} |