@@ -1387,16 +1387,23 @@ private KeyDeserializer _createEnumKeyDeserializer(DeserializationContext ctxt,
1387
1387
throws JsonMappingException
1388
1388
{
1389
1389
final DeserializationConfig config = ctxt .getConfig ();
1390
+ Class <?> enumClass = type .getRawClass ();
1391
+
1390
1392
BeanDescription beanDesc = config .introspect (type );
1391
- JsonDeserializer <?> des = findDeserializerFromAnnotation (ctxt , beanDesc .getClassInfo ());
1393
+ // 24-Sep-2015, bim: a key deserializer is the preferred thing.
1394
+ KeyDeserializer des = findKeyDeserializerFromAnnotation (ctxt , beanDesc .getClassInfo ());
1392
1395
if (des != null ) {
1393
- return StdKeyDeserializers .constructDelegatingKeyDeserializer (config , type , des );
1394
- }
1395
- Class <?> enumClass = type .getRawClass ();
1396
- // 23-Nov-2010, tatu: Custom deserializer?
1397
- JsonDeserializer <?> custom = _findCustomEnumDeserializer (enumClass , config , beanDesc );
1398
- if (custom != null ) {
1399
- return StdKeyDeserializers .constructDelegatingKeyDeserializer (config , type , custom );
1396
+ return des ;
1397
+ } else {
1398
+ // 24-Sep-2015, bim: if no key deser, look for enum deserializer first, then a plain deser.
1399
+ JsonDeserializer <?> custom = _findCustomEnumDeserializer (enumClass , config , beanDesc );
1400
+ if (custom != null ) {
1401
+ return StdKeyDeserializers .constructDelegatingKeyDeserializer (config , type , custom );
1402
+ }
1403
+ JsonDeserializer <?> valueDesForKey = findDeserializerFromAnnotation (ctxt , beanDesc .getClassInfo ());
1404
+ if (valueDesForKey != null ) {
1405
+ return StdKeyDeserializers .constructDelegatingKeyDeserializer (config , type , valueDesForKey );
1406
+ }
1400
1407
}
1401
1408
1402
1409
EnumResolver enumRes = constructEnumResolver (enumClass , config , beanDesc .findJsonValueMethod ());
@@ -1728,6 +1735,22 @@ protected JsonDeserializer<Object> findDeserializerFromAnnotation(Deserializatio
1728
1735
return ctxt .deserializerInstance (ann , deserDef );
1729
1736
}
1730
1737
1738
+ /**
1739
+ * Helper method called to check if a class or method
1740
+ * has annotation that tells which class to use for deserialization.
1741
+ * Returns null if no such annotation found.
1742
+ */
1743
+ protected KeyDeserializer findKeyDeserializerFromAnnotation (DeserializationContext ctxt ,
1744
+ Annotated ann )
1745
+ throws JsonMappingException
1746
+ {
1747
+ Object deserDef = ctxt .getAnnotationIntrospector ().findKeyDeserializer (ann );
1748
+ if (deserDef == null ) {
1749
+ return null ;
1750
+ }
1751
+ return ctxt .keyDeserializerInstance (ann , deserDef );
1752
+ }
1753
+
1731
1754
/**
1732
1755
* Method called to see if given method has annotations that indicate
1733
1756
* a more specific type than what the argument specifies.
0 commit comments