File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
src/test/java/com/fasterxml/jackson/dataformat/xml/deser Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff 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
12152.18.1 (28 -Oct-2024 )
1316
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments