diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index 305f3b65c2..a36fc474ef 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
-wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
diff --git a/pom.xml b/pom.xml
index 3728c5cd96..e43b8115a1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -321,7 +321,6 @@
maven-compiler-plugintrue
- true1414
@@ -375,7 +374,6 @@
maven-compiler-plugintrue
- true1717
diff --git a/src/main/java/com/fasterxml/jackson/databind/JavaType.java b/src/main/java/com/fasterxml/jackson/databind/JavaType.java
index aae3285a3d..1323b52ac5 100644
--- a/src/main/java/com/fasterxml/jackson/databind/JavaType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/JavaType.java
@@ -254,7 +254,9 @@ public JavaType forcedNarrowBy(Class> subclass)
}
@Deprecated // since 2.7
- protected abstract JavaType _narrow(Class> subclass);
+ protected JavaType _narrow(Class> subclass) {
+ return this;
+ }
/*
/**********************************************************************
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
index 0ce19c8689..b263403d64 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
@@ -1993,8 +1993,9 @@ public ObjectMapper activateDefaultTyping(PolymorphicTypeValidator ptv,
TypeResolverBuilder> typer = _constructDefaultTypeResolverBuilder(applicability, ptv);
// we'll always use full class name, when using defaulting
- typer = typer.init(JsonTypeInfo.Id.CLASS, null);
- typer = typer.inclusion(includeAs);
+ JsonTypeInfo.Value typeInfo = JsonTypeInfo.Value.construct(JsonTypeInfo.Id.CLASS, includeAs,
+ null, null, false, null);
+ typer = typer.init(typeInfo, null);
return setDefaultTyping(typer);
}
@@ -2023,9 +2024,9 @@ public ObjectMapper activateDefaultTypingAsProperty(PolymorphicTypeValidator ptv
TypeResolverBuilder> typer = _constructDefaultTypeResolverBuilder(applicability,
ptv);
// we'll always use full class name, when using defaulting
- typer = typer.init(JsonTypeInfo.Id.CLASS, null);
- typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
- typer = typer.typeProperty(propertyName);
+ JsonTypeInfo.Value typeInfo = JsonTypeInfo.Value.construct(JsonTypeInfo.Id.CLASS, JsonTypeInfo.As.PROPERTY,
+ propertyName, null, false, null);
+ typer = typer.init(typeInfo, null);
return setDefaultTyping(typer);
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
index dfeaee6888..2b94b737d9 100644
--- a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
+++ b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
@@ -1508,27 +1508,29 @@ protected PropertyName _findConstructorName(Annotated a)
protected TypeResolverBuilder> _findTypeResolver(MapperConfig> config,
Annotated ann, JavaType baseType)
{
+ // since 2.16 : backporting {@link JsonTypeInfo.Value} from 3.0
+ JsonTypeInfo.Value typeInfo = findPolymorphicTypeInfo(config, ann);
+
// First: maybe we have explicit type resolver?
TypeResolverBuilder> b;
- JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class);
JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class);
if (resAnn != null) {
- if (info == null) {
+ if (typeInfo == null) {
return null;
}
// let's not try to force access override (would need to pass
// settings through if we did, since that's not doable on some platforms)
b = config.typeResolverBuilderInstance(ann, resAnn.value());
} else { // if not, use standard one, if indicated by annotations
- if (info == null) {
+ if (typeInfo == null) {
return null;
}
// bit special; must return 'marker' to block use of default typing:
- if (info.use() == JsonTypeInfo.Id.NONE) {
+ if (typeInfo.getIdType() == JsonTypeInfo.Id.NONE) {
return _constructNoTypeResolverBuilder();
}
- b = _constructStdTypeResolverBuilder();
+ b = _constructStdTypeResolverBuilder(config, typeInfo, baseType);
}
// Does it define a custom type id resolver?
JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class);
@@ -1537,35 +1539,36 @@ protected TypeResolverBuilder> _findTypeResolver(MapperConfig> config,
if (idRes != null) {
idRes.init(baseType);
}
- b = b.init(info.use(), idRes);
// 13-Aug-2011, tatu: One complication; external id only works for properties;
// so if declared for a Class, we will need to map it to "PROPERTY"
// instead of "EXTERNAL_PROPERTY"
- JsonTypeInfo.As inclusion = info.include();
+ JsonTypeInfo.As inclusion = typeInfo.getInclusionType();
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY && (ann instanceof AnnotatedClass)) {
- inclusion = JsonTypeInfo.As.PROPERTY;
+ typeInfo = typeInfo.withInclusionType(JsonTypeInfo.As.PROPERTY);
}
- b = b.inclusion(inclusion);
- b = b.typeProperty(info.property());
- Class> defaultImpl = info.defaultImpl();
+ Class> defaultImpl = typeInfo.getDefaultImpl();
// 08-Dec-2014, tatu: To deprecate `JsonTypeInfo.None` we need to use other placeholder(s);
// and since `java.util.Void` has other purpose (to indicate "deser as null"), we'll instead
// use `JsonTypeInfo.class` itself. But any annotation type will actually do, as they have no
// valid use (cannot instantiate as default)
- if (defaultImpl != JsonTypeInfo.None.class && !defaultImpl.isAnnotation()) {
- b = b.defaultImpl(defaultImpl);
+ if (defaultImpl != null && defaultImpl != JsonTypeInfo.None.class && !defaultImpl.isAnnotation()) {
+ typeInfo = typeInfo.withDefaultImpl(defaultImpl);
}
- b = b.typeIdVisibility(info.visible());
+
+ b = b.init(typeInfo, idRes);
return b;
}
/**
* Helper method for constructing standard {@link TypeResolverBuilder}
* implementation.
+ *
+ * @since 2.16, backported from 3.0
*/
- protected StdTypeResolverBuilder _constructStdTypeResolverBuilder() {
- return new StdTypeResolverBuilder();
+ protected TypeResolverBuilder> _constructStdTypeResolverBuilder(MapperConfig> config,
+ JsonTypeInfo.Value typeInfo, JavaType baseType) {
+ return new StdTypeResolverBuilder(typeInfo);
}
/**
diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder.java
index d1d592866b..10dfd83f12 100644
--- a/src/main/java/com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder.java
+++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/TypeResolverBuilder.java
@@ -98,6 +98,24 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
*/
public T init(JsonTypeInfo.Id idType, TypeIdResolver res);
+ /**
+ * Initialization method that is called right after constructing
+ * the builder instance, in cases where information could not be
+ * passed directly (for example when instantiated for an annotation)
+ *
+ * NOTE: This method is abstract in Jackson 3.0, at the moment of writing.
+ *
+ * @param settings Configuration settings to apply.
+ *
+ * @return Resulting builder instance (usually this builder,
+ * but not necessarily)
+ *
+ * @since 2.16 (backported from Jackson 3.0)
+ */
+ default T init(JsonTypeInfo.Value settings, TypeIdResolver res) {
+ return init(settings.getIdType(), res);
+ }
+
/*
/**********************************************************
/* Methods for configuring resolver to build
diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java
index a98b92c0ed..32da2e1795 100644
--- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java
+++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.databind.jsontype.impl;
+import com.fasterxml.jackson.databind.introspect.Annotated;
import java.util.Collection;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@@ -35,6 +36,11 @@ public class StdTypeResolverBuilder
*/
protected boolean _typeIdVisible = false;
+ /**
+ * @since 2.16 (backported from Jackson 3.0)
+ */
+ protected Boolean _requireTypeIdForSubtypes;
+
/**
* Default class to use in case type information is not available
* or is broken.
@@ -78,10 +84,40 @@ protected StdTypeResolverBuilder(StdTypeResolverBuilder base,
_customIdResolver = base._customIdResolver;
_defaultImpl = defaultImpl;
+ _requireTypeIdForSubtypes = base._requireTypeIdForSubtypes;
+ }
+
+ /**
+ * @since 2.16 (backported from Jackson 3.0)
+ */
+ public StdTypeResolverBuilder(JsonTypeInfo.Value settings) {
+ if (settings != null) {
+ _idType = settings.getIdType();
+ if (_idType == null) {
+ throw new IllegalArgumentException("idType cannot be null");
+ }
+ _includeAs = settings.getInclusionType();
+ _typeProperty = _propName(settings.getPropertyName(), _idType);
+ _defaultImpl = settings.getDefaultImpl();
+ _typeIdVisible = settings.getIdVisible();
+ _requireTypeIdForSubtypes = settings.getRequireTypeIdForSubtypes();
+ }
+ }
+
+ /**
+ * @since 2.16 (backported from Jackson 3.0)
+ */
+ protected static String _propName(String propName, JsonTypeInfo.Id idType) {
+ if (propName == null) {
+ propName = idType.getDefaultPropertyName();
+ }
+ return propName;
}
public static StdTypeResolverBuilder noTypeInfoBuilder() {
- return new StdTypeResolverBuilder().init(JsonTypeInfo.Id.NONE, null);
+ JsonTypeInfo.Value typeInfo = JsonTypeInfo.Value.construct(JsonTypeInfo.Id.NONE, null,
+ null, null, false, null);
+ return new StdTypeResolverBuilder().init(typeInfo, null);
}
@Override
@@ -98,6 +134,31 @@ public StdTypeResolverBuilder init(JsonTypeInfo.Id idType, TypeIdResolver idRes)
return this;
}
+ @Override
+ public StdTypeResolverBuilder init(JsonTypeInfo.Value settings,
+ TypeIdResolver idRes)
+ {
+ _customIdResolver = idRes;
+
+ if (settings != null) {
+ _idType = settings.getIdType();
+ if (_idType == null) {
+ throw new IllegalArgumentException("idType cannot be null");
+ }
+ _includeAs = settings.getInclusionType();
+
+ // Let's also initialize property name as per idType default
+ _typeProperty = settings.getPropertyName();
+ if (_typeProperty == null) {
+ _typeProperty = _idType.getDefaultPropertyName();
+ }
+ _typeIdVisible = settings.getIdVisible();
+ _defaultImpl = settings.getDefaultImpl();
+ _requireTypeIdForSubtypes = settings.getRequireTypeIdForSubtypes();
+ }
+ return this;
+ }
+
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config,
JavaType baseType, Collection subtypes)
@@ -436,11 +497,11 @@ protected boolean _strictTypeIdHandling(DeserializationConfig config, JavaType b
*
* @return true if the class has type resolver annotations, false otherwise
*
- * @since 2.15
+ * @since 2.15, using {@code ai.findPolymorphicTypeInfo(config, ac)} since 2.16.
*/
protected boolean _hasTypeResolver(DeserializationConfig config, JavaType baseType) {
AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, baseType.getRawClass());
AnnotationIntrospector ai = config.getAnnotationIntrospector();
- return ai.findTypeResolver(config, ac, baseType) != null;
+ return ai.findPolymorphicTypeInfo(config, ac) != 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 877ebe4436..5b6d655667 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java
@@ -106,16 +106,6 @@ public ArrayType withStaticTyping() {
/**********************************************************
*/
- /**
- * Handling of narrowing conversions for arrays is trickier: for now,
- * it is not even allowed.
- */
- @Override
- @Deprecated // since 2.7
- protected JavaType _narrow(Class> subclass) {
- return _reportUnsupported();
- }
-
// Should not be called, as array types in Java are not extensible; but
// let's not freak out even if it is called?
@Override
@@ -124,10 +114,6 @@ public JavaType refine(Class> contentClass, TypeBindings bindings,
return null;
}
- private JavaType _reportUnsupported() {
- throw new UnsupportedOperationException("Cannot narrow or widen array types");
- }
-
/*
/**********************************************************
/* Overridden methods
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 fd4179a466..64422dc5f4 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/CollectionLikeType.java
@@ -89,14 +89,6 @@ public static CollectionLikeType upgradeFrom(JavaType baseType, JavaType element
throw new IllegalArgumentException("Cannot upgrade from an instance of "+baseType.getClass());
}
- @Override
- @Deprecated // since 2.7
- protected JavaType _narrow(Class> subclass) {
- return new CollectionLikeType(subclass, _bindings,
- _superClass, _superInterfaces, _elementType,
- _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 e8b176c500..ecf985dc9e 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/CollectionType.java
@@ -61,13 +61,6 @@ public static CollectionType construct(Class> rawType, JavaType elemT) {
null, null, false);
}
- @Deprecated // since 2.7
- @Override
- protected JavaType _narrow(Class> subclass) {
- return new CollectionType(subclass, _bindings,
- _superClass, _superInterfaces, _elementType, null, null, _asStatic);
- }
-
@Override
public JavaType withContentType(JavaType contentType) {
if (_elementType == contentType) {
diff --git a/src/main/java/com/fasterxml/jackson/databind/type/IterationType.java b/src/main/java/com/fasterxml/jackson/databind/type/IterationType.java
new file mode 100644
index 0000000000..1892a39533
--- /dev/null
+++ b/src/main/java/com/fasterxml/jackson/databind/type/IterationType.java
@@ -0,0 +1,29 @@
+package com.fasterxml.jackson.databind.type;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+/**
+ * Specialized {@link SimpleType} for types that are allow iteration
+ * over Collection(-like) types: this includes types like
+ * {@link java.util.Iterator}.
+ * Referenced type is accessible using {@link #getContentType()}.
+ *
+ * @since 2.16
+ */
+public abstract class IterationType extends SimpleType
+{
+ private static final long serialVersionUID = 1L;
+
+ protected final JavaType _iteratedType;
+
+ /**
+ * Constructor used when upgrading into this type (via {@link #upgradeFrom},
+ * the usual way for {@link IterationType}s to come into existence.
+ * Sets up what is considered the "base" reference type
+ */
+ protected IterationType(TypeBase base, JavaType iteratedType)
+ {
+ super(base);
+ _iteratedType = iteratedType;
+ }
+}
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 d745e981e4..36342b9b81 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java
@@ -87,15 +87,6 @@ public static MapLikeType construct(Class> rawType, JavaType keyT,
null, keyT, valueT, null, null, false);
}
- @Deprecated
- // since 2.7
- @Override
- protected JavaType _narrow(Class> subclass) {
- return new MapLikeType(subclass, _bindings, _superClass,
- _superInterfaces, _keyType, _valueType, _valueHandler,
- _typeHandler, _asStatic);
- }
-
/**
* @since 2.7
*/
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 cec9166db3..a469298eea 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/MapType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/MapType.java
@@ -57,14 +57,6 @@ public static MapType construct(Class> rawType, JavaType keyT, JavaType valueT
keyT, valueT, null, null, false);
}
- @Deprecated // since 2.7
- @Override
- protected JavaType _narrow(Class> subclass) {
- return new MapType(subclass, _bindings,
- _superClass, _superInterfaces, _keyType, _valueType,
- _valueHandler, _typeHandler, _asStatic);
- }
-
@Override
public MapType withTypeHandler(Object h) {
return new MapType(_class, _bindings,
diff --git a/src/main/java/com/fasterxml/jackson/databind/type/PlaceholderForType.java b/src/main/java/com/fasterxml/jackson/databind/type/PlaceholderForType.java
index 31b17de881..4ffa28fff4 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/PlaceholderForType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/PlaceholderForType.java
@@ -83,12 +83,6 @@ public JavaType refine(Class> rawType, TypeBindings bindings, JavaType superCl
return _unsupported();
}
- @Override
- @Deprecated // since 2.7
- protected JavaType _narrow(Class> subclass) {
- return _unsupported();
- }
-
@Override
public boolean isContainerType() {
return false;
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 271c4a5458..11d2e8322b 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java
@@ -25,7 +25,10 @@ public class ReferenceType extends SimpleType
* if being sub-classed.
*
* @since 2.8
+ *
+ * @deprecated Since 2.16
*/
+ @Deprecated
protected final JavaType _anchorType;
protected ReferenceType(Class> cls, TypeBindings bindings,
@@ -137,10 +140,9 @@ public ReferenceType withContentValueHandler(Object h) {
if (h == _referencedType.