-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.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,78 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.util.*; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
// For [dataformat-xml#509] | ||
public class UnexpectedNonWhitespaceText509Test { | ||
@JsonPropertyOrder({ "key", "content" }) | ||
static class Data { | ||
@JacksonXmlText | ||
public String content; | ||
@JacksonXmlProperty(isAttribute=true) | ||
protected java.lang.String key; | ||
|
||
public java.lang.String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(java.lang.String value) { | ||
this.key = value; | ||
} | ||
} | ||
|
||
static class MetaData { | ||
protected List<Data> data; | ||
|
||
public List<Data> getData() { | ||
if (data == null) { | ||
data = new ArrayList<>(); | ||
} | ||
return this.data; | ||
} | ||
|
||
public void setData(List<Data> data) { | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Objects.toString(data); | ||
} | ||
} | ||
|
||
private final XmlMapper XML_MAPPER = new XmlMapper(); | ||
|
||
@Test | ||
public void testDeSerData() throws Exception { | ||
Data value = deSer("<data key=\"MadeWith\">Text Editor</data>", Data.class); | ||
assertEquals("\"key\" attribute not correctly deserialized", value.getKey(), "MadeWith"); | ||
} | ||
|
||
@Test | ||
public void testDeSerMetaData() throws Exception { | ||
MetaData value = deSer("<metaData>\n" // | ||
+ " <data key=\"MadeWith\">Text Editor</data>\n" // | ||
+ " <data key=\"Version\">1.0.0</data>\n" // | ||
+ "</metaData>", MetaData.class); | ||
List<Data> entries = value.getData(); | ||
assertEquals("\"data\" not correctly deserialized", entries.size(), 2); | ||
Data entry = entries.get(0); | ||
assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "MadeWith"); | ||
entry = entries.get(1); | ||
assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "Version"); | ||
} | ||
|
||
private <T> T deSer(String xmlString, Class<T> clazz) throws Exception { | ||
return XML_MAPPER.readerFor(clazz).readValue(xmlString); | ||
} | ||
} |