Skip to content

Commit af91d91

Browse files
committed
Merge branch '2.7'
2 parents e4dd521 + 958c824 commit af91d91

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

release-notes/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Project: jackson-databind
6666
#1277: Add caching of resolved generic types for `TypeFactory`
6767
(requested by Andriy P)
6868

69-
2.7.6 (not yet released)
69+
2.7.6 (23-Jul-2016)
7070

7171
#1215: Problem with type specialization for Maps with `@JsonDeserialize(as=subtype)`
7272
(reported by brentryan@github)

src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ public static JsonSerializer<Object> getStdKeySerializer(SerializationConfig con
7272
* @since 2.7
7373
*/
7474
public static JsonSerializer<Object> getFallbackKeySerializer(SerializationConfig config,
75-
Class<?> rawKeyType) {
75+
Class<?> rawKeyType)
76+
{
7677
if (rawKeyType != null) {
7778
// 29-Sep-2015, tatu: Odd case here, of `Enum`, which we may get for `EnumMap`; not sure
7879
// if that is a bug or feature. Regardless, it seems to require dynamic handling
7980
// (compared to getting actual fully typed Enum).
8081
// Note that this might even work from the earlier point, but let's play it safe for now
82+
// 11-Aug-2016, tatu: Turns out we get this if `EnumMap` is the root value because
83+
// then there is no static type
8184
if (rawKeyType == Enum.class) {
8285
return new Dynamic();
8386
}

src/test/java/com/fasterxml/jackson/databind/ser/TestEnumSerialization.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private EnumWithJsonValue(String n) {
6161
@JsonValue
6262
public String external() { return "value:"+name; }
6363
}
64-
64+
6565
protected static interface ToStringMixin {
6666
@Override
6767
@JsonValue public String toString();
@@ -215,6 +215,12 @@ private LC749Enum() { }
215215
public String toString() { return name().toLowerCase(); }
216216
}
217217

218+
// for [databind#1322]
219+
protected enum EnumWithJsonProperty {
220+
@JsonProperty("aleph")
221+
A;
222+
}
223+
218224
/*
219225
/**********************************************************
220226
/* Tests
@@ -254,8 +260,7 @@ public void testSubclassedEnums() throws Exception
254260
assertEquals("\"B\"", MAPPER.writeValueAsString(EnumWithSubClass.B));
255261
}
256262

257-
public void testEnumsWithJsonValue() throws Exception
258-
{
263+
public void testEnumsWithJsonValue() throws Exception {
259264
assertEquals("\"value:bar\"", MAPPER.writeValueAsString(EnumWithJsonValue.B));
260265
}
261266

@@ -415,6 +420,18 @@ public void testEnumMapSerEnableToString() throws Exception {
415420
m.put(LC749Enum.A, "value");
416421
assertEquals("{\"a\":\"value\"}", w.writeValueAsString(m));
417422
}
423+
424+
// [databind#1322]
425+
public void testEnumsWithJsonProperty() throws Exception {
426+
assertEquals(quote("aleph"), MAPPER.writeValueAsString(EnumWithJsonProperty.A));
427+
}
428+
429+
// [databind#1322]
430+
public void testEnumsWithJsonPropertyInSet() throws Exception
431+
{
432+
assertEquals("[\"aleph\"]",
433+
MAPPER.writeValueAsString(EnumSet.of(EnumWithJsonProperty.A)));
434+
}
418435
}
419436

420437
// [JACKSON-757], non-inner enum
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.EnumMap;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.databind.BaseMapTest;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
public class EnumSerialization1322Test extends BaseMapTest
10+
{
11+
// for [databind#1322]
12+
protected enum EnumWithJsonProperty {
13+
@JsonProperty("aleph")
14+
A;
15+
}
16+
17+
private final ObjectMapper MAPPER = new ObjectMapper();
18+
19+
// [databind#1322]
20+
public void testEnumsWithJsonPropertyAsKey() throws Exception
21+
{
22+
EnumMap<EnumWithJsonProperty,String> input = new EnumMap<EnumWithJsonProperty,String>(EnumWithJsonProperty.class);
23+
input.put(EnumWithJsonProperty.A, "b");
24+
assertEquals("{\"aleph\":\"b\"}", MAPPER.writeValueAsString(input));
25+
}
26+
}

0 commit comments

Comments
 (0)