|
| 1 | +package com.fasterxml.jackson.dataformat.xml.lists; |
| 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.JacksonXmlRootElement; |
| 9 | + |
| 10 | +public class ListDeser307Test extends XmlTestBase |
| 11 | +{ |
| 12 | + @JacksonXmlRootElement(localName = "customer") |
| 13 | + public class CustomerWithoutWrapper { |
| 14 | + public Long customerId; |
| 15 | + public String customerName; |
| 16 | + |
| 17 | + @JacksonXmlElementWrapper(useWrapping = false) |
| 18 | + public List<Account> account; |
| 19 | + } |
| 20 | + |
| 21 | + public class Account { |
| 22 | + public Long accountId; |
| 23 | + public String accountName; |
| 24 | + public String postcode; |
| 25 | + } |
| 26 | + |
| 27 | + /* |
| 28 | + /******************************************************** |
| 29 | + /* Test methods |
| 30 | + /******************************************************** |
| 31 | + */ |
| 32 | + |
| 33 | + private final ObjectMapper MAPPER = newMapper(); |
| 34 | + |
| 35 | + // [dataformat-xml#307] |
| 36 | + public void testListDeser307() throws Exception |
| 37 | + { |
| 38 | + final String XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + |
| 39 | + "<customer xmlns=\"http://www.archer-tech.com/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + |
| 40 | + " <customerId>1</customerId>\n" + |
| 41 | + " <customerName>Michael Judy</customerName>\n" + |
| 42 | + " <account>\n" + |
| 43 | + " <accountId>100</accountId>\n" + |
| 44 | + " <accountName>Michael</accountName>\n" + |
| 45 | + " <postcode xsi:nil=\"true\"></postcode>\n" + |
| 46 | + " </account>\n" + |
| 47 | + " <account>\n" + |
| 48 | + " <accountId>200</accountId>\n" + |
| 49 | + " <accountName>Judy</accountName>\n" + |
| 50 | + " <postcode xsi:nil=\"true\"></postcode>\n" + |
| 51 | + " </account> \n" + |
| 52 | + "</customer>"; |
| 53 | + CustomerWithoutWrapper result = |
| 54 | + MAPPER.readValue(XML, CustomerWithoutWrapper.class); |
| 55 | + assertNotNull(result); |
| 56 | + assertNotNull(result.account); |
| 57 | + assertEquals(2, result.account.size()); |
| 58 | + } |
| 59 | +} |
0 commit comments