|
| 1 | +package com.fasterxml.jackson.dataformat.xml.failing; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 7 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 8 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 9 | +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; |
| 10 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; |
| 11 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; |
| 12 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; |
| 13 | + |
| 14 | +// 13-Nov-2020, tatu: Not quite sure how to configure test to pass; |
| 15 | +// seems like it should work but does not. Leaving for future generations |
| 16 | +// to figure out... |
| 17 | +public class ElementWrapperViaCreator149Test extends XmlTestBase |
| 18 | +{ |
| 19 | + @JacksonXmlRootElement(localName="body") |
| 20 | + static class Body149 { |
| 21 | + final String type; |
| 22 | + |
| 23 | + @JacksonXmlProperty(localName="label") |
| 24 | + final List<String> labels; |
| 25 | + |
| 26 | + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) |
| 27 | + public Body149(@JacksonXmlProperty(localName="type") |
| 28 | + String type, |
| 29 | + @JacksonXmlElementWrapper(localName="labels") |
| 30 | + @JacksonXmlProperty(localName="label") |
| 31 | + List<String> labels) |
| 32 | + { |
| 33 | + this.type = type; |
| 34 | + this.labels = labels; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /* |
| 39 | + /********************************************************************** |
| 40 | + /* Test methods |
| 41 | + /********************************************************************** |
| 42 | + */ |
| 43 | + |
| 44 | + private final ObjectMapper MAPPER = newMapper(); |
| 45 | + |
| 46 | + // [dataformat-xml#149] |
| 47 | + public void testElementWrapper149() throws Exception |
| 48 | + { |
| 49 | + final String XML = "<body>\n" + |
| 50 | + " <type>TYPE</type>\n" + |
| 51 | + " <labels><label>foo</label><label>bar</label></labels>\n" + |
| 52 | + "</body>"; |
| 53 | + Body149 result = MAPPER.readValue(XML, Body149.class); |
| 54 | + assertEquals("TYPE", result.type); |
| 55 | + assertNotNull(result.labels); |
| 56 | + assertEquals(Arrays.asList("foo", "bar"), result.labels); |
| 57 | + |
| 58 | +//System.err.println("XML: "+MAPPER.writeValueAsString(result)); |
| 59 | + } |
| 60 | +} |
0 commit comments