|
3 | 3 | import java.io.*;
|
4 | 4 | import java.util.*;
|
5 | 5 |
|
6 |
| -import com.fasterxml.jackson.annotation.JsonAnyGetter; |
7 |
| -import com.fasterxml.jackson.annotation.JsonFormat; |
| 6 | +import com.fasterxml.jackson.annotation.*; |
8 | 7 | import com.fasterxml.jackson.annotation.JsonFormat.Shape;
|
9 |
| -import com.fasterxml.jackson.annotation.JsonProperty; |
10 |
| -import com.fasterxml.jackson.annotation.JsonValue; |
| 8 | + |
11 | 9 | import com.fasterxml.jackson.core.*;
|
12 | 10 | import com.fasterxml.jackson.databind.*;
|
13 | 11 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
@@ -207,6 +205,14 @@ public void serialize(Foo661 value, JsonGenerator jgen, SerializerProvider provi
|
207 | 205 | }
|
208 | 206 | }
|
209 | 207 | }
|
| 208 | + |
| 209 | + protected static enum LC749Enum { |
| 210 | + A, B, C; |
| 211 | + private LC749Enum() { } |
| 212 | + @Override |
| 213 | + public String toString() { return name().toLowerCase(); } |
| 214 | + } |
| 215 | + |
210 | 216 | /*
|
211 | 217 | /**********************************************************
|
212 | 218 | /* Tests
|
@@ -384,6 +390,31 @@ public void testCustomEnumMapKeySerializer() throws Exception {
|
384 | 390 | String json = MAPPER.writeValueAsString(new MyBean661("abc"));
|
385 | 391 | assertEquals(aposToQuotes("{'X-FOO':'abc'}"), json);
|
386 | 392 | }
|
| 393 | + |
| 394 | + // [databind#749] |
| 395 | + |
| 396 | + public void testEnumMapSerDefault() throws Exception { |
| 397 | + final ObjectMapper mapper = new ObjectMapper(); |
| 398 | + EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class); |
| 399 | + m.put(LC749Enum.A, "value"); |
| 400 | + assertEquals("{\"A\":\"value\"}", mapper.writeValueAsString(m)); |
| 401 | + } |
| 402 | + |
| 403 | + public void testEnumMapSerDisableToString() throws Exception { |
| 404 | + final ObjectMapper mapper = new ObjectMapper(); |
| 405 | + ObjectWriter w = mapper.writer().without(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); |
| 406 | + EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class); |
| 407 | + m.put(LC749Enum.A, "value"); |
| 408 | + assertEquals("{\"A\":\"value\"}", w.writeValueAsString(m)); |
| 409 | + } |
| 410 | + |
| 411 | + public void testEnumMapSerEnableToString() throws Exception { |
| 412 | + final ObjectMapper mapper = new ObjectMapper(); |
| 413 | + ObjectWriter w = mapper.writer().with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); |
| 414 | + EnumMap<LC749Enum, String> m = new EnumMap<LC749Enum, String>(LC749Enum.class); |
| 415 | + m.put(LC749Enum.A, "value"); |
| 416 | + assertEquals("{\"a\":\"value\"}", w.writeValueAsString(m)); |
| 417 | + } |
387 | 418 | }
|
388 | 419 |
|
389 | 420 | // [JACKSON-757], non-inner enum
|
|
0 commit comments