|
3 | 3 | import java.io.*;
|
4 | 4 | import java.util.*;
|
5 | 5 |
|
| 6 | +import com.fasterxml.jackson.annotation.JsonAnyGetter; |
6 | 7 | import com.fasterxml.jackson.annotation.JsonFormat;
|
7 | 8 | import com.fasterxml.jackson.annotation.JsonFormat.Shape;
|
8 | 9 | import com.fasterxml.jackson.annotation.JsonProperty;
|
@@ -182,6 +183,30 @@ public MyStuff594(String value) {
|
182 | 183 | }
|
183 | 184 | }
|
184 | 185 |
|
| 186 | + public class MyBean661 { |
| 187 | + private Map<Foo661, String> foo = new EnumMap<Foo661, String>(Foo661.class); |
| 188 | + |
| 189 | + public MyBean661(String value) { |
| 190 | + foo.put(Foo661.FOO, value); |
| 191 | + } |
| 192 | + |
| 193 | + @JsonAnyGetter |
| 194 | + @JsonSerialize(keyUsing = Foo661.Serializer.class) |
| 195 | + public Map<Foo661, String> getFoo() { |
| 196 | + return foo; |
| 197 | + } |
| 198 | + } |
| 199 | + |
| 200 | + enum Foo661 { |
| 201 | + FOO; |
| 202 | + public static class Serializer extends JsonSerializer<Foo661> { |
| 203 | + @Override |
| 204 | + public void serialize(Foo661 value, JsonGenerator jgen, SerializerProvider provider) |
| 205 | + throws IOException { |
| 206 | + jgen.writeFieldName("X-"+value.name()); |
| 207 | + } |
| 208 | + } |
| 209 | + } |
185 | 210 | /*
|
186 | 211 | /**********************************************************
|
187 | 212 | /* Tests
|
@@ -340,6 +365,12 @@ public void testJsonValueForEnumMapKey() throws Exception {
|
340 | 365 | assertEquals(aposToQuotes("{'stuff':{'longValue':'foo'}}"),
|
341 | 366 | mapper.writeValueAsString(new MyStuff594("foo")));
|
342 | 367 | }
|
| 368 | + |
| 369 | + // [databind#661] |
| 370 | + public void testCustomEnumMapKeySerializer() throws Exception { |
| 371 | + String json = mapper.writeValueAsString(new MyBean661("abc")); |
| 372 | + assertEquals(aposToQuotes("{'X-FOO':'abc'}"), json); |
| 373 | + } |
343 | 374 | }
|
344 | 375 |
|
345 | 376 | // [JACKSON-757], non-inner enum
|
|
0 commit comments