diff --git a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java index 749b8c3c08..bdbb89377e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java @@ -1039,7 +1039,8 @@ public JavaType refineDeserializationType(final MapperConfig config, final Annotated a, final JavaType baseType) throws JsonMappingException { JavaType type = baseType; - + final TypeFactory tf = config.getTypeFactory(); + // 10-Oct-2015, tatu: For 2.7, we'll need to delegate back to // now-deprecated secondary methods; this because while // direct sub-class not yet retrofitted may only override @@ -1048,14 +1049,14 @@ public JavaType refineDeserializationType(final MapperConfig config, // Ok: start by refining the main type itself; common to all types - Class contentClass = findDeserializationType(a, type); - if ((contentClass != null) && !type.hasRawClass(contentClass)) { + Class valueClass = findDeserializationType(a, type); + if ((valueClass != null) && !type.hasRawClass(valueClass)) { try { - type = config.getTypeFactory().constructSpecializedType(type, contentClass); + type = tf.constructSpecializedType(type, valueClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, String.format("Failed to narrow type %s with annotation (value %s), from '%s': %s", - type, contentClass.getName(), a.getName(), iae.getMessage()), + type, valueClass.getName(), a.getName(), iae.getMessage()), iae); } } @@ -1075,16 +1076,18 @@ public JavaType refineDeserializationType(final MapperConfig config, } } } - if (type.getContentType() != null) { // collection[like], map[like], array, reference + JavaType contentType = type.getContentType(); + if (contentType != null) { // collection[like], map[like], array, reference // And then value types for all containers: - Class valueClass = findDeserializationContentType(a, type.getContentType()); - if (valueClass != null) { + Class contentClass = findDeserializationContentType(a, type.getContentType()); + if (contentClass != null) { try { - type = type.narrowContentsBy(valueClass); + contentType = tf.constructSpecializedType(contentType, contentClass); + type = type.withContentType(contentType); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, String.format("Failed to narrow value type of %s with concrete-type annotation (value %s), from '%s': %s", - type, valueClass.getName(), a.getName(), iae.getMessage()), + type, contentClass.getName(), a.getName(), iae.getMessage()), iae); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/JavaType.java b/src/main/java/com/fasterxml/jackson/databind/JavaType.java index f36ae38898..95b19a8cab 100644 --- a/src/main/java/com/fasterxml/jackson/databind/JavaType.java +++ b/src/main/java/com/fasterxml/jackson/databind/JavaType.java @@ -210,8 +210,6 @@ public JavaType forcedNarrowBy(Class subclass) protected abstract JavaType _narrow(Class subclass); - public abstract JavaType narrowContentsBy(Class contentClass); - /** * Mutant factory method that will try to create and return a sub-type instance * for known parameterized types; for other types will return `null` to indicate diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeDeserializerBase.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeDeserializerBase.java index ef865d1ab1..198fdcdeb6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeDeserializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/TypeDeserializerBase.java @@ -82,6 +82,7 @@ protected TypeDeserializerBase(JavaType baseType, TypeIdResolver idRes, * not entirely safe... however, since Collections/Maps are * seldom (if ever) base types, may be ok. */ + // 01-Nov-2015, tatu: Actually this is still exactly wrong. Should fix. _defaultImpl = baseType.forcedNarrowBy(defaultImpl); } _property = null; diff --git a/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java b/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java index bc8fbcd1ee..132fbf297c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java @@ -115,19 +115,6 @@ protected JavaType _narrow(Class subclass) { return _reportUnsupported(); } - /** - * For array types, both main type and content type can be modified; - * but ultimately they are interchangeable. - */ - @Override - public JavaType narrowContentsBy(Class contentClass) { - if (contentClass == _componentType.getRawClass()) { - return this; - } - return construct(_componentType.narrowBy(contentClass), _bindings, - _valueHandler, _typeHandler); - } - // Should not be called, as array types in Java are not extensible; but // let's not freak out even if it is called? @Override diff --git a/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java b/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java index e7bdf2c011..2c54913be1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java @@ -78,18 +78,6 @@ protected JavaType _narrow(Class subclass) { _valueHandler, _typeHandler, _asStatic); } - @Override - public JavaType narrowContentsBy(Class contentClass) - { - // Can do a quick check first: - if (contentClass == _elementType.getRawClass()) { - return this; - } - return new CollectionLikeType(_class, _bindings, - _superClass, _superInterfaces, _elementType.narrowBy(contentClass), - _valueHandler, _typeHandler, _asStatic); - } - @Override public JavaType withContentType(JavaType contentType) { if (_elementType == contentType) { diff --git a/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java b/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java index af32f8d097..ec5cee5b27 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java @@ -58,18 +58,6 @@ protected JavaType _narrow(Class subclass) { _superClass, _superInterfaces, _elementType, null, null, _asStatic); } - @Override - public JavaType narrowContentsBy(Class contentClass) - { - // Can do a quick check first: - if (contentClass == _elementType.getRawClass()) { - return this; - } - return new CollectionType(_class, _bindings, - _superClass, _superInterfaces, _elementType.narrowBy(contentClass), - _valueHandler, _typeHandler, _asStatic); - } - @Override public JavaType withContentType(JavaType contentType) { if (_elementType == contentType) { diff --git a/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java b/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java index 666988bec8..ae4b513060 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java @@ -78,18 +78,6 @@ protected JavaType _narrow(Class subclass) { _superClass, _superInterfaces, _keyType, _valueType, _valueHandler, _typeHandler, _asStatic); } - @Override - public JavaType narrowContentsBy(Class contentClass) - { - // Can do a quick check first: - if (contentClass == _valueType.getRawClass()) { - return this; - } - return new MapLikeType(_class, _bindings, - _superClass, _superInterfaces, _keyType, _valueType.narrowBy(contentClass), - _valueHandler, _typeHandler, _asStatic); - } - public JavaType narrowKey(Class keySubclass) { // Can do a quick check first: diff --git a/src/main/java/com/fasterxml/jackson/databind/type/MapType.java b/src/main/java/com/fasterxml/jackson/databind/type/MapType.java index 97c364cd22..755ab3be50 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/MapType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/MapType.java @@ -51,18 +51,6 @@ protected JavaType _narrow(Class subclass) { _valueHandler, _typeHandler, _asStatic); } - @Override - public JavaType narrowContentsBy(Class contentClass) - { - // Can do a quick check first: - if (contentClass == _valueType.getRawClass()) { - return this; - } - return new MapType(_class, _bindings, - _superClass, _superInterfaces, _keyType, _valueType.narrowBy(contentClass), - _valueHandler, _typeHandler, _asStatic); - } - @Override public JavaType narrowKey(Class keySubclass) { diff --git a/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java b/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java index 3bdd47bb83..844128a4aa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java @@ -67,7 +67,16 @@ public static ReferenceType construct(Class cls, JavaType refType) { return new ReferenceType(cls, TypeBindings.emptyBindings(), // !!! TODO: missing supertypes null, null, refType, null, null, false); - } + } + + @Override + public JavaType withContentType(JavaType contentType) { + if (_referencedType == contentType) { + return this; + } + return new ReferenceType(_class, _bindings, _superClass, _superInterfaces, + contentType, _valueHandler, _typeHandler, _asStatic); + } @Override public ReferenceType withTypeHandler(Object h) @@ -152,21 +161,6 @@ protected JavaType _narrow(Class subclass) _valueHandler, _typeHandler, _asStatic); } - // no need to override _widen() since it by default just calls _narrow() anyway -// protected JavaType _widen(Class subclass) - - @Override - public JavaType narrowContentsBy(Class contentClass) - { - // Can do a quick check first: - if (_referencedType.hasRawClass(contentClass)) { - return this; - } - return new ReferenceType(_class, _bindings, - _superClass, _superInterfaces, _referencedType.narrowBy(contentClass), - _valueHandler, _typeHandler, _asStatic); - } - /* /********************************************************** /* Public API overrides diff --git a/src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java b/src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java index c57bc0fde0..0895e688e3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java @@ -73,11 +73,6 @@ protected JavaType _narrow(Class subclass) { return this; } - @Override - public JavaType narrowContentsBy(Class contentClass) { - return this; - } - @Override public JavaType refine(Class rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) { diff --git a/src/main/java/com/fasterxml/jackson/databind/type/SimpleType.java b/src/main/java/com/fasterxml/jackson/databind/type/SimpleType.java index c7acfd0927..1744880f22 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/SimpleType.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/SimpleType.java @@ -84,13 +84,6 @@ protected JavaType _narrow(Class subclass) _valueHandler, _typeHandler, _asStatic); } - @Override - public JavaType narrowContentsBy(Class subclass) - { - // should never get called - throw new IllegalArgumentException("Internal error: SimpleType.narrowContentsBy() should never be called"); - } - public static SimpleType construct(Class cls) { /* Let's add sanity checks, just to ensure no