Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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("<Country>Italy</Country>", xml);

assertEquals(Country.ITALY, MAPPER.readValue(xml, Country.class));
}
}