Skip to content

Commit 7e35baa

Browse files
authored
Add test for #682 (passing with jackson-databind fix) (#685)
1 parent 5b78983 commit 7e35baa

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Project: jackson-dataformat-xml
88

99
#678: XML module not registered correctly when setting a custom `SerializerFactory`
1010
(reported by @SimonCockx)
11+
#682: `MismatchedInputException` encountered while deserializing XML to an Enum type
12+
using a factory method
13+
(reported by @WannabeSoftwareEngineer)
1114

1215
2.18.1 (28-Oct-2024)
1316

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.dataformat.xml.deser;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
import com.fasterxml.jackson.annotation.JsonCreator;
5+
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
7+
8+
public class EnumDeser682Test extends XmlTestBase
9+
{
10+
static enum Country {
11+
ITALY("Italy"),
12+
NETHERLANDS("Netherlands");
13+
14+
@JsonValue
15+
final String value;
16+
17+
Country(String value) {
18+
this.value = value;
19+
}
20+
21+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
22+
public static Country fromValue(String value) {
23+
for (Country b : Country.values()) {
24+
if (b.value.equals(value)) {
25+
return b;
26+
}
27+
}
28+
throw new IllegalArgumentException("Unexpected value '" + value + "'");
29+
}
30+
}
31+
32+
private final ObjectMapper MAPPER = newMapper();
33+
34+
public void testEnumDeser682() throws Exception {
35+
String xml = MAPPER.writeValueAsString(Country.ITALY);
36+
assertEquals("<Country>Italy</Country>", xml);
37+
38+
assertEquals(Country.ITALY, MAPPER.readValue(xml, Country.class));
39+
}
40+
}

0 commit comments

Comments
 (0)