Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
228bc0e
Add tests for `Record` deserialization regression and related (#3921)
JooHyukKim May 22, 2023
79c232f
Backport findPolymorphicTypeInfo
JooHyukKim May 19, 2023
8cabbd9
Clean up unnccessary change.
JooHyukKim May 19, 2023
0b30af1
Use Value class around TypeResolverBuilder
JooHyukKim May 20, 2023
a509ac2
Clean up changes
JooHyukKim May 20, 2023
97c14f1
Add version changes in StdTypeResolverBuilder
JooHyukKim May 20, 2023
3b77339
Replace usage of TypeResolverBuilder.init
JooHyukKim May 20, 2023
57b740e
Apply review
JooHyukKim May 22, 2023
04b8ed2
Add behavioral test regarding `transient` field with annotation (#3951)
JooHyukKim May 23, 2023
3505990
Update Maven wrapper version
cowtowncoder May 23, 2023
8753e8a
Merge branch '2.15' into 2.16
cowtowncoder May 23, 2023
58b9fc9
Backport `TypeResolverBuilder` initialization mechanisms from Jackson…
JooHyukKim May 23, 2023
cc02b19
remove obsolete "optimize" property
cowtowncoder May 23, 2023
a42a015
Start work on #3950: add skeletal IterationType (to merge to 3.0)
cowtowncoder May 23, 2023
dcffc41
Minor removal of deprecated "narrow" method implementation from JavaT…
cowtowncoder May 23, 2023
f878a66
...
cowtowncoder May 23, 2023
9991ffc
Backport findPolymorphicTypeInfo
JooHyukKim May 19, 2023
3cb02a4
Clean up unnccessary change.
JooHyukKim May 19, 2023
bcb1c27
Use Value class around TypeResolverBuilder
JooHyukKim May 20, 2023
0d472b3
Clean up changes
JooHyukKim May 20, 2023
8d63f67
Add version changes in StdTypeResolverBuilder
JooHyukKim May 20, 2023
94a66c6
Replace usage of TypeResolverBuilder.init
JooHyukKim May 20, 2023
3d5d2a8
Apply review
JooHyukKim May 22, 2023
c30d8a6
Remove unnccessary changes
JooHyukKim May 23, 2023
93983d3
Merge branch 'Introduce-JsonTypeInfo.Value' of https://github.com/Joo…
JooHyukKim May 23, 2023
3761d1b
Remove conflicting change in TypeResolverBuilder
JooHyukKim May 23, 2023
90edb76
Revert "Merge branch 'Introduce-JsonTypeInfo.Value' of https://github…
JooHyukKim May 23, 2023
7fdc0e7
Backport findPolymorphicTypeInfo
JooHyukKim May 19, 2023
d8d3990
Clean up unnccessary change.
JooHyukKim May 19, 2023
dd6054a
Use Value class around TypeResolverBuilder
JooHyukKim May 20, 2023
4386503
Clean up changes
JooHyukKim May 20, 2023
e628ddc
Add version changes in StdTypeResolverBuilder
JooHyukKim May 20, 2023
5e5d3b4
Replace usage of TypeResolverBuilder.init
JooHyukKim May 20, 2023
669ca81
Apply review
JooHyukKim May 22, 2023
deee3a9
Remove conflicting change in TypeResolverBuilder
JooHyukKim May 23, 2023
176d904
Revert "Merge branch 'Introduce-JsonTypeInfo.Value' of https://github…
JooHyukKim May 23, 2023
c200afd
Merge branch 'Introduce-JsonTypeInfo.Value' of https://github.com/Joo…
JooHyukKim May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<optimize>true</optimize>
<!-- Enable Java 14+ for all sources so that Intellij picks the right language level -->
<source>14</source>
<release>14</release>
Expand Down Expand Up @@ -375,7 +374,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<optimize>true</optimize>
<!-- Enable Java 17 for all sources so that Intellij picks the right language level -->
<source>17</source>
<release>17</release>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/fasterxml/jackson/databind/JavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
/**********************************************************************
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* <p>
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,6 +36,11 @@ public class StdTypeResolverBuilder
*/
protected boolean _typeIdVisible = false;

/**
* @since 2.16 (backported from Jackson 3.0)
*/
protected Boolean _requireTypeIdForSubtypes;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this field should be included in this PR, but #3891


/**
* Default class to use in case type information is not available
* or is broken.
Expand Down Expand Up @@ -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
Expand All @@ -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<NamedType> subtypes)
Expand Down Expand Up @@ -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;
}
}
14 changes: 0 additions & 14 deletions src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading