11package com .fasterxml .jackson .dataformat .xml .deser ;
22
3+ import com .fasterxml .jackson .annotation .JsonCreator ;
4+ import com .fasterxml .jackson .annotation .JsonValue ;
5+
36import com .fasterxml .jackson .dataformat .xml .*;
47
58public 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