|
| 1 | +package tools.jackson.dataformat.xml.tofix.records; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import tools.jackson.dataformat.xml.XmlMapper; |
| 8 | +import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; |
| 9 | +import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty; |
| 10 | +import tools.jackson.dataformat.xml.annotation.JacksonXmlText; |
| 11 | +import tools.jackson.dataformat.xml.testutil.failure.JacksonTestFailureExpected; |
| 12 | + |
| 13 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 14 | +import static tools.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT; |
| 15 | +import static tools.jackson.databind.cfg.DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS; |
| 16 | + |
| 17 | +// [dataformat-xml#615] |
| 18 | +public class EntityRecordList615Test { |
| 19 | + |
| 20 | + record EntityRecord(@JacksonXmlText |
| 21 | + @JsonProperty("kto") |
| 22 | + String kto, |
| 23 | + @JacksonXmlProperty(isAttribute = true, localName = "Hkto") |
| 24 | + @JsonProperty("hkto") |
| 25 | + String hkto) { |
| 26 | + } |
| 27 | + |
| 28 | + record EntityRecordList(@JacksonXmlElementWrapper(localName = "entities") |
| 29 | + @JsonProperty("entity") |
| 30 | + List<EntityRecord> entityRecordList) { |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + @JacksonTestFailureExpected |
| 35 | + void testXmlDeser() { |
| 36 | + XmlMapper xmlMapper = XmlMapper.builder() |
| 37 | + .defaultUseWrapper(false) |
| 38 | + .disable(WRITE_DATES_AS_TIMESTAMPS) |
| 39 | + .enable(ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) |
| 40 | + .build(); |
| 41 | + |
| 42 | + String xmlString = |
| 43 | + """ |
| 44 | + <?xml version="1.0" encoding="UTF-8"?> |
| 45 | + <EntityrecordList> |
| 46 | + <entities> |
| 47 | + <kto Hkto="6543210000">4561230000</kto> |
| 48 | + <kto Hkto="6543210000">5678910012</kto> |
| 49 | + <kto Hkto="">5678910013</kto> |
| 50 | + <kto Hkto="654321">567891</kto> |
| 51 | + <kto>5678910014</kto> |
| 52 | + <kto>567891</kto> |
| 53 | + </entities> |
| 54 | + </EntityrecordList>"""; |
| 55 | + |
| 56 | + EntityRecordList entityRecordList = |
| 57 | + xmlMapper.readValue(xmlString, EntityRecordList.class); |
| 58 | + assertNotNull(entityRecordList); |
| 59 | + } |
| 60 | +} |
0 commit comments