-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
85823f4
commit 8d18b78
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EmptyBeanDeser318Test.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,102 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; | ||
|
||
public class EmptyBeanDeser318Test extends XmlTestBase | ||
{ | ||
static class Wrapper { | ||
@JacksonXmlProperty(localName = "id") | ||
String id; | ||
@JacksonXmlProperty(localName = "nested") | ||
Nested nested; | ||
} | ||
|
||
static class Nested { | ||
@JacksonXmlProperty(localName = "nested2") | ||
Nested2 nested2; | ||
} | ||
|
||
static class Nested2 { | ||
@JacksonXmlProperty(localName = "attr", isAttribute = true) | ||
String attr; | ||
@JacksonXmlText | ||
String value; | ||
} | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods | ||
/********************************************************************** | ||
*/ | ||
|
||
private final XmlMapper MAPPER = newMapper(); | ||
|
||
public void testEmptyString() throws Exception { | ||
String s = "<wrapper>" | ||
+ " <id>id</id>" | ||
+ " <nested></nested>" | ||
+ "</wrapper>"; | ||
|
||
Wrapper value = MAPPER.readValue(s, Wrapper.class); | ||
assertEquals("id", value.id); | ||
assertNull(value.nested); | ||
} | ||
|
||
public void testBlankString() throws Exception { | ||
String s = "<wrapper>" | ||
+ " <id>id</id>" | ||
+ " <nested> </nested>" | ||
+ "</wrapper>"; | ||
|
||
// This fails with the following exception: | ||
// com.fasterxml.jackson.databind.exc.MismatchedInputException: | ||
// Cannot construct instance of `JacksonXMLTest$Nested` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (' ') | ||
Wrapper value = MAPPER.readValue(s, Wrapper.class); | ||
assertEquals("id", value.id); | ||
assertNull(value.nested); | ||
} | ||
|
||
public void testBlankString2() throws Exception { | ||
String s = "<wrapper>" | ||
+ " <id>id</id>" | ||
+ " <nested> </nested>" | ||
+ "</wrapper>"; | ||
|
||
// This fails with the following exception: | ||
// com.fasterxml.jackson.databind.exc.MismatchedInputException: | ||
// Cannot construct instance of `JacksonXMLTest$Nested` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (' ') | ||
Wrapper value = MAPPER.readerFor(Wrapper.class) | ||
.with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) | ||
.readValue(s); | ||
assertEquals("id", value.id); | ||
assertNull(value.nested); | ||
} | ||
|
||
public void testMissing() throws Exception { | ||
String s = "<wrapper>" | ||
+ " <id>id</id>" | ||
+ "</wrapper>"; | ||
|
||
Wrapper value = MAPPER.readValue(s, Wrapper.class); | ||
assertEquals("id", value.id); | ||
assertNull(value.nested); | ||
} | ||
|
||
public void testValidStructure() throws Exception { | ||
String s = "<wrapper>" | ||
+ " <id>id</id>" | ||
+ " <nested>" | ||
+ " <nested2 attr=\"test\"><![CDATA[Some text]]></nested2>" | ||
+ " </nested>" | ||
+ "</wrapper>"; | ||
|
||
Wrapper value = MAPPER.readValue(s, Wrapper.class); | ||
assertEquals("id", value.id); | ||
assertEquals("test", value.nested.nested2.attr); | ||
assertEquals("Some text", value.nested.nested2.value); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser319Test.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,31 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class ListDeser319Test extends XmlTestBase | ||
{ | ||
static class Value319 { | ||
public Long orderId, orderTypeId; | ||
} | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods | ||
/********************************************************************** | ||
*/ | ||
|
||
private final XmlMapper MAPPER = newMapper(); | ||
|
||
public void testEmptyList319() throws Exception | ||
{ | ||
final String DOC = "<orders></orders>"; | ||
List<Value319> value = MAPPER.readValue(DOC, | ||
new TypeReference<List<Value319>>() { }); | ||
assertNotNull(value); | ||
assertEquals(0, value.size()); | ||
} | ||
} |