diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 9850d168..2e866131 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -8,6 +8,9 @@ Project: jackson-dataformat-xml #678: XML module not registered correctly when setting a custom `SerializerFactory` (reported by @SimonCockx) +#682: `MismatchedInputException` encountered while deserializing XML to an Enum type + using a factory method + (reported by @WannabeSoftwareEngineer) 2.18.1 (28-Oct-2024) diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeser682Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeser682Test.java new file mode 100644 index 00000000..3562221c --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeser682Test.java @@ -0,0 +1,40 @@ +package com.fasterxml.jackson.dataformat.xml.deser; + +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.dataformat.xml.XmlTestBase; + +public class EnumDeser682Test extends XmlTestBase +{ + static enum Country { + ITALY("Italy"), + NETHERLANDS("Netherlands"); + + @JsonValue + final String value; + + Country(String value) { + this.value = value; + } + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + public static Country fromValue(String value) { + for (Country b : Country.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + private final ObjectMapper MAPPER = newMapper(); + + public void testEnumDeser682() throws Exception { + String xml = MAPPER.writeValueAsString(Country.ITALY); + assertEquals("Italy", xml); + + assertEquals(Country.ITALY, MAPPER.readValue(xml, Country.class)); + } +}