From 6ad860cf4b3f9ba43e7a74a701c48881f305f253 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 28 Apr 2020 15:55:19 -0700 Subject: [PATCH] Add failing test for #393 --- .../xml/failing/Issue393DeserTest.java | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue393DeserTest.java diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue393DeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue393DeserTest.java new file mode 100644 index 000000000..c179737e1 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue393DeserTest.java @@ -0,0 +1,134 @@ +package com.fasterxml.jackson.dataformat.xml.failing; + +import java.util.*; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +public class Issue393DeserTest extends XmlTestBase +{ + @JacksonXmlRootElement(localName = "result") + @JsonInclude(JsonInclude.Include.NON_NULL) + static class Value393 { + private Prices prices = new Prices(); + + public void setPrices(Prices prices) { + this.prices = prices; + } + + @JacksonXmlProperty(localName = "prices") + public Prices getPrices() { + return this.prices; + } + } + +// @JsonIgnoreProperties(ignoreUnknown = true) + @JacksonXmlRootElement(localName = "prices") + static class Prices { + private List price = new ArrayList(); + + public void setPrice(List price) { + this.price = price; + } + + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "price") + public List getPrice() { + return this.price; + } + } + +// @JacksonXmlRootElement(localName = "price") +// @JsonIgnoreProperties(ignoreUnknown = true) + static class Price { + private String price; + private String num; + + protected Price() { } + public Price(String p, String n) { + price = p; + num = n; + } + + public void setPrice(String price) { + this.price = price; + } + + @JacksonXmlProperty(localName = "price") + public String getPrice() { + return this.price; + } + + public void setNum(String num) { + this.num = num; + } + + @JacksonXmlProperty(localName = "num") + public String getNum() { + return this.num; + } + } + + /* + /******************************************************** + /* Test methods + /******************************************************** + */ + + private final ObjectMapper MAPPER = newMapper(); + + // [dataform#393] + public void testDeser393() throws Exception + { + // for debugging: +/* + Value393 input = new Value393(); + Prices prices = new Prices(); + prices.setPrice(Arrays.asList( + new Price("100", "7.0"), + new Price("100", "4.0") + )); + input.setPrices(prices); + + String xml = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input); + System.out.println("XML:\n"+xml); +*/ +/* + String content = //"\n" + "\n" + + "\n" + + " \n" + + " \n" + + " 100\n" + + " 7.0\n" + + " \n" + + " \n" + + " 100\n" + + " 4.0\n" + + " " + + " \n" + + ""; + Value393 result = MAPPER.readValue(content, Value393.class); + assertNotNull(result); +*/ + + String content = + "\n" + + " \n" + + " 100\n" + + " 7.0\n" + + " \n" + + " \n" + + " 100\n" + + " 4.0\n" + + " " + + "\n"; + Prices result = MAPPER.readValue(content, Prices.class); + assertNotNull(result); + } +}