|
| 1 | +package com.fasterxml.jackson.dataformat.xml.failing; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; |
| 7 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; |
| 8 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; |
| 9 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; |
| 10 | + |
| 11 | +public class ElementWithIntAndAttr412Test extends XmlTestBase |
| 12 | +{ |
| 13 | + @JacksonXmlRootElement(localName = "container") |
| 14 | + static class Bean412 { |
| 15 | + @JacksonXmlProperty(localName = "values") |
| 16 | + @JacksonXmlElementWrapper(useWrapping = false) |
| 17 | + List<TaggedInt412> v; |
| 18 | + } |
| 19 | + |
| 20 | + @JacksonXmlRootElement(localName = "tagged") |
| 21 | + static class TaggedInt412 { |
| 22 | + @JacksonXmlProperty |
| 23 | + public int id; |
| 24 | + |
| 25 | + @JacksonXmlProperty |
| 26 | + public int count; |
| 27 | + } |
| 28 | + |
| 29 | + /* |
| 30 | + /********************************************************** |
| 31 | + /* Test methods |
| 32 | + /********************************************************** |
| 33 | + */ |
| 34 | + |
| 35 | + private final ObjectMapper MAPPER = newMapper(); |
| 36 | + |
| 37 | + // [dataformat-xml#412] |
| 38 | + public void testIntFromElemAndAttrInList() throws Exception |
| 39 | + { |
| 40 | + String XML = "<container>\n" |
| 41 | + + " <values>\n" |
| 42 | + + " <id bar='baz'>2812</id>\n" |
| 43 | + + " <count>15</count>\n" |
| 44 | + + " </values>\n" |
| 45 | + + " <values>\n" |
| 46 | + + " <count>42</count>\n" |
| 47 | + + " <id arg='oof'>1235</id>\n" |
| 48 | + + " </values>\n" |
| 49 | + + "</container>"; |
| 50 | + Bean412 many = MAPPER.readValue(XML, Bean412.class); |
| 51 | + assertNotNull(many.v); |
| 52 | +//System.err.println("XML:\n"+MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(many)); |
| 53 | + assertEquals(2, many.v.size()); |
| 54 | + assertEquals(2812, many.v.get(0).id); |
| 55 | + assertEquals(15, many.v.get(0).count); |
| 56 | + assertEquals(1235, many.v.get(1).id); |
| 57 | + assertEquals(42, many.v.get(1).count); |
| 58 | + } |
| 59 | + |
| 60 | + public void testIntFromElemAndAttr() throws Exception |
| 61 | + { |
| 62 | + String XML = "<tagged>\n" |
| 63 | + + " <id bar='baz'>2812</id>\n" |
| 64 | + + " <count>15</count>\n" |
| 65 | + + "</tagged>"; |
| 66 | + TaggedInt412 result = MAPPER.readValue(XML, TaggedInt412.class); |
| 67 | + assertEquals(2812, result.id); |
| 68 | + assertEquals(15, result.count); |
| 69 | + |
| 70 | + XML = " <tagged>\n" |
| 71 | + + " <count>42</count>\n" |
| 72 | + + " <id arg='oof'>1235</id>\n" |
| 73 | + + " </tagged>\n"; |
| 74 | + |
| 75 | + result = MAPPER.readValue(XML, TaggedInt412.class); |
| 76 | + assertEquals(1235, result.id); |
| 77 | + assertEquals(42, result.count); |
| 78 | + } |
| 79 | +} |
0 commit comments