Skip to content

Commit 44dffb2

Browse files
committed
Merge branch '2.18' into 2.19
2 parents d4b6ad1 + 0a7cf7b commit 44dffb2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

release-notes/VERSION-2.x

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

1313
#678: XML module not registered correctly when setting a custom `SerializerFactory`
1414
(reported by @SimonCockx)
15+
#682: `MismatchedInputException` encountered while deserializing XML to an Enum type
16+
using a factory method
17+
(reported by @WannabeSoftwareEngineer)
1518

1619
2.18.1 (28-Oct-2024)
1720

src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeserTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.fasterxml.jackson.dataformat.xml.deser;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
36
import com.fasterxml.jackson.dataformat.xml.*;
47

58
public class EnumDeserTest extends XmlTestBase
@@ -14,6 +17,29 @@ public EnumBean() { }
1417
public EnumBean(TestEnum v) { value = v; }
1518
}
1619

20+
// [dataformat-xml#682]
21+
static enum Country682 {
22+
ITALY("Italy"),
23+
NETHERLANDS("Netherlands");
24+
25+
@JsonValue
26+
final String value;
27+
28+
Country682(String value) {
29+
this.value = value;
30+
}
31+
32+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
33+
public static Country682 fromValue(String value) {
34+
for (Country682 b : Country682.values()) {
35+
if (b.value.equals(value)) {
36+
return b;
37+
}
38+
}
39+
throw new IllegalArgumentException("Unexpected value '" + value + "'");
40+
}
41+
}
42+
1743
/*
1844
/**********************************************************
1945
/* Unit tests
@@ -38,4 +64,12 @@ public void testRootEnum() throws Exception
3864
assertNotNull(result);
3965
assertEquals(TestEnum.B, result);
4066
}
67+
68+
// [dataformat-xml#682]
69+
public void testEnumDeser682() throws Exception {
70+
String xml = MAPPER.writeValueAsString(Country682.ITALY);
71+
assertEquals("<Country682>Italy</Country682>", xml);
72+
73+
assertEquals(Country682.ITALY, MAPPER.readValue(xml, Country682.class));
74+
}
4175
}

0 commit comments

Comments
 (0)