Skip to content

Commit 7e62d7e

Browse files
committed
Merge branch '2.4'
Conflicts: src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java
2 parents 785c456 + fd4eb1b commit 7e62d7e

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

release-notes/CREDITS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Chris Cleveland:
139139
Benson Margulies:
140140
* Reported #467: Unwanted POJO's embedded in tree via serialization to tree
141141
(2.4.0)
142+
* Reported #601: ClassCastException for a custom serializer for enum key in `EnumMap`
143+
(2.4.4)
142144

143145
Steve Sanbeg: (sanbeg@github)
144146
* Contributed #482: Make date parsing error behavior consistent with JDK

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project: jackson-databind
5757
(reported by Jerbell@github)
5858
#592: Wrong `TokenBuffer` delegate deserialization using `@JsonCreator`
5959
(reported by Eugene L)
60+
#601: ClassCastException for a custom serializer for enum key in `EnumMap`
61+
(reported by Benson M)
6062
#604: `Map` deserializers not being cached, causing performance problems
6163
- Minor fix to `EnumSerializer` regarding detection "serialize using index"
6264
- Minor fix to number serializers, to call proper callback for schema generation

src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,8 @@ protected JsonSerializer<?> buildMapSerializer(SerializationConfig config,
720720
if (ser != null) { break; }
721721
}
722722
if (ser == null) {
723-
/* 05-Nov-2014, tatu: As per [databind#601], may be easier NOT to use specialized
724-
* serializers, if custom serialization of keys is needed.
725-
*/
723+
// 08-Nov-2014, tatu: As per [databind#601], better just use default Map serializer
724+
/*
726725
if (EnumMap.class.isAssignableFrom(type.getRawClass())
727726
&& ((keySerializer == null) || ClassUtil.isJacksonStdImpl(keySerializer))) {
728727
JavaType keyType = type.getKeyType();
@@ -736,17 +735,17 @@ protected JsonSerializer<?> buildMapSerializer(SerializationConfig config,
736735
ser = new EnumMapSerializer(type.getContentType(), staticTyping, enums,
737736
elementTypeSerializer, elementValueSerializer);
738737
} else {
739-
Object filterId = findFilterId(config, beanDesc);
740-
MapSerializer mapSer = MapSerializer.construct(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()),
738+
*/
739+
Object filterId = findFilterId(config, beanDesc);
740+
MapSerializer mapSer = MapSerializer.construct(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()),
741741
type, staticTyping, elementTypeSerializer,
742742
keySerializer, elementValueSerializer, filterId);
743-
Object suppressableValue = findSuppressableContentValue(config,
744-
type.getContentType(), beanDesc);
745-
if (suppressableValue != null) {
746-
mapSer = mapSer.withContentInclusion(suppressableValue);
747-
}
748-
ser = mapSer;
743+
Object suppressableValue = findSuppressableContentValue(config,
744+
type.getContentType(), beanDesc);
745+
if (suppressableValue != null) {
746+
mapSer = mapSer.withContentInclusion(suppressableValue);
749747
}
748+
ser = mapSer;
750749
}
751750
// [Issue#120]: Allow post-processing
752751
if (_factoryConfig.hasSerializerModifiers()) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
* Specialized serializer for {@link EnumMap}s. Somewhat tricky to
2626
* implement because actual Enum value type may not be available;
2727
* and if not, it can only be gotten from actual instance.
28+
*
29+
* @deprecated Since 2.4.4; standard {@link MapSerializer} works better.
2830
*/
2931
@JacksonStdImpl
32+
@Deprecated
3033
public class EnumMapSerializer
3134
extends ContainerSerializer<EnumMap<? extends Enum<?>, ?>>
3235
implements ContextualSerializer

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,11 @@ public void testSubclassedEnums() throws Exception
203203
assertEquals("\"B\"", mapper.writeValueAsString(EnumWithSubClass.B));
204204
}
205205

206-
// [JACKSON-193]
207206
public void testEnumsWithJsonValue() throws Exception
208207
{
209208
assertEquals("\"bar\"", mapper.writeValueAsString(EnumWithJsonValue.B));
210209
}
211210

212-
// also, for [JACKSON-193], needs to work via mix-ins
213211
public void testEnumsWithJsonValueUsingMixin() throws Exception
214212
{
215213
// can't share, as new mix-ins are added
@@ -218,6 +216,14 @@ public void testEnumsWithJsonValueUsingMixin() throws Exception
218216
assertEquals("\"b\"", m.writeValueAsString(TestEnum.B));
219217
}
220218

219+
// [databind#601]
220+
public void testEnumsWithJsonValueInMap() throws Exception
221+
{
222+
EnumMap<EnumWithJsonValue,String> input = new EnumMap<EnumWithJsonValue,String>(EnumWithJsonValue.class);
223+
input.put(EnumWithJsonValue.B, "x");
224+
assertEquals("{\""+EnumWithJsonValue.B.toString()+"\":\"x\"}", mapper.writeValueAsString(input));
225+
}
226+
221227
/**
222228
* Test for ensuring that @JsonSerializable is used with Enum types as well
223229
* as with any other types.

0 commit comments

Comments
 (0)