From bc0adc282d8bc1f617cdac3934cc8abbcf5d26d2 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Thu, 19 Oct 2023 20:27:50 +0200 Subject: [PATCH] Create reproducer test case for #509 (#604) --- .../UnexpectedNonWhitespaceText509Test.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java new file mode 100644 index 000000000..0059dbc4c --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnexpectedNonWhitespaceText509Test.java @@ -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; + + public List getData() { + if (data == null) { + data = new ArrayList<>(); + } + return this.data; + } + + public void setData(List 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("Text Editor", Data.class); + assertEquals("\"key\" attribute not correctly deserialized", value.getKey(), "MadeWith"); + } + + @Test + public void testDeSerMetaData() throws Exception { + MetaData value = deSer("\n" // + + " Text Editor\n" // + + " 1.0.0\n" // + + "", MetaData.class); + List 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 deSer(String xmlString, Class clazz) throws Exception { + return XML_MAPPER.readerFor(clazz).readValue(xmlString); + } +}