Skip to content

Commit

Permalink
Add test for #682 (passing with jackson-databind fix) (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 25, 2024
1 parent 5b78983 commit 7e35baa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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));
}
}

0 comments on commit 7e35baa

Please sign in to comment.