File tree 1 file changed +29
-0
lines changed
src/test/java/com/fasterxml/jackson/databind/format
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .fasterxml .jackson .databind .format ;
2
2
3
+ import java .util .Collections ;
4
+ import java .util .Map ;
5
+
3
6
import com .fasterxml .jackson .annotation .*;
4
7
import com .fasterxml .jackson .annotation .JsonFormat .Shape ;
5
8
@@ -70,6 +73,24 @@ static class ColorWrapper {
70
73
}
71
74
}
72
75
76
+ // [databind#2576]
77
+ @ JsonFormat (shape = JsonFormat .Shape .OBJECT )
78
+ public enum Enum2576 {
79
+ DEFAULT ("default" ),
80
+ ATTRIBUTES ("attributes" ) {
81
+ @ Override
82
+ public String toString () {
83
+ return name ();
84
+ }
85
+ };
86
+
87
+ private final String key ;
88
+ private Enum2576 (String key ) {
89
+ this .key = key ;
90
+ }
91
+ public String getKey () { return this .key ; }
92
+ }
93
+
73
94
/*
74
95
/**********************************************************
75
96
/* Tests
@@ -113,4 +134,12 @@ public void testEnumPropertyAsNumber() throws Exception {
113
134
assertEquals (String .format (aposToQuotes ("{'color':%s}" ), Color .GREEN .ordinal ()),
114
135
MAPPER .writeValueAsString (new ColorWrapper (Color .GREEN )));
115
136
}
137
+
138
+ // [databind#2576]
139
+ public void testEnumWithMethodOverride () throws Exception {
140
+ String stringResult = MAPPER .writeValueAsString (Enum2576 .ATTRIBUTES );
141
+ Map <?,?> result = MAPPER .readValue (stringResult , Map .class );
142
+ Map <String ,String > exp = Collections .singletonMap ("key" , "attributes" );
143
+ assertEquals (exp , result );
144
+ }
116
145
}
You can’t perform that action at this time.
0 commit comments