File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
src/test/java/com/fasterxml/jackson/dataformat/xml/deser Expand file tree Collapse file tree 2 files changed +52
-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+ private String value ;
15+
16+ Country (String value ) {
17+ this .value = value ;
18+ }
19+
20+ @ JsonValue
21+ public String getValue () {
22+ return value ;
23+ }
24+
25+ @ Override
26+ public String toString () {
27+ return String .valueOf (value );
28+ }
29+
30+ @ JsonCreator (mode = JsonCreator .Mode .DELEGATING )
31+ public static Country fromValue (String value ) {
32+ for (Country b : Country .values ()) {
33+ if (b .value .equals (value )) {
34+ return b ;
35+ }
36+ }
37+ throw new IllegalArgumentException ("Unexpected value '" + value + "'" );
38+ }
39+ }
40+
41+ private final ObjectMapper MAPPER = newMapper ();
42+
43+ public void testEnumDeser682 () throws Exception {
44+ String xml = MAPPER .writeValueAsString (Country .ITALY );
45+ assertEquals ("<Country>Italy</Country>" , xml );
46+
47+ assertEquals (Country .ITALY , MAPPER .readValue (xml , Country .class ));
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments