Skip to content

Commit 79c232f

Browse files
committed
Backport findPolymorphicTypeInfo
1 parent a815f04 commit 79c232f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,24 +1508,29 @@ protected PropertyName _findConstructorName(Annotated a)
15081508
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config,
15091509
Annotated ann, JavaType baseType)
15101510
{
1511+
// since 2.16 : backporting {@link JsonTypeInfo.Value} from 3.0
1512+
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
1513+
JsonTypeInfo.Value typeInfo = ai.findPolymorphicTypeInfo(config, ann);
1514+
1515+
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class);
1516+
15111517
// First: maybe we have explicit type resolver?
15121518
TypeResolverBuilder<?> b;
1513-
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class);
15141519
JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class);
15151520

15161521
if (resAnn != null) {
1517-
if (info == null) {
1522+
if (typeInfo == null) {
15181523
return null;
15191524
}
15201525
// let's not try to force access override (would need to pass
15211526
// settings through if we did, since that's not doable on some platforms)
15221527
b = config.typeResolverBuilderInstance(ann, resAnn.value());
15231528
} else { // if not, use standard one, if indicated by annotations
1524-
if (info == null) {
1529+
if (typeInfo == null) {
15251530
return null;
15261531
}
15271532
// bit special; must return 'marker' to block use of default typing:
1528-
if (info.use() == JsonTypeInfo.Id.NONE) {
1533+
if (typeInfo.getIdType() == JsonTypeInfo.Id.NONE) {
15291534
return _constructNoTypeResolverBuilder();
15301535
}
15311536
b = _constructStdTypeResolverBuilder();
@@ -1537,26 +1542,26 @@ protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config,
15371542
if (idRes != null) {
15381543
idRes.init(baseType);
15391544
}
1540-
b = b.init(info.use(), idRes);
1545+
b = b.init(typeInfo.getIdType(), idRes);
15411546
// 13-Aug-2011, tatu: One complication; external id only works for properties;
15421547
// so if declared for a Class, we will need to map it to "PROPERTY"
15431548
// instead of "EXTERNAL_PROPERTY"
1544-
JsonTypeInfo.As inclusion = info.include();
1549+
JsonTypeInfo.As inclusion = typeInfo.getInclusionType();
15451550
if (inclusion == JsonTypeInfo.As.EXTERNAL_PROPERTY && (ann instanceof AnnotatedClass)) {
15461551
inclusion = JsonTypeInfo.As.PROPERTY;
15471552
}
15481553
b = b.inclusion(inclusion);
1549-
b = b.typeProperty(info.property());
1550-
Class<?> defaultImpl = info.defaultImpl();
1554+
b = b.typeProperty(typeInfo.getPropertyName());
1555+
Class<?> defaultImpl = typeInfo.getDefaultImpl();
15511556

15521557
// 08-Dec-2014, tatu: To deprecate `JsonTypeInfo.None` we need to use other placeholder(s);
15531558
// and since `java.util.Void` has other purpose (to indicate "deser as null"), we'll instead
15541559
// use `JsonTypeInfo.class` itself. But any annotation type will actually do, as they have no
15551560
// valid use (cannot instantiate as default)
1556-
if (defaultImpl != JsonTypeInfo.None.class && !defaultImpl.isAnnotation()) {
1561+
if (defaultImpl != null && defaultImpl != JsonTypeInfo.None.class && !defaultImpl.isAnnotation()) {
15571562
b = b.defaultImpl(defaultImpl);
15581563
}
1559-
b = b.typeIdVisibility(info.visible());
1564+
b = b.typeIdVisibility(typeInfo.getIdVisible());
15601565
return b;
15611566
}
15621567

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.databind.jsontype.impl;
22

3+
import com.fasterxml.jackson.databind.introspect.Annotated;
34
import java.util.Collection;
45

56
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@@ -436,11 +437,11 @@ protected boolean _strictTypeIdHandling(DeserializationConfig config, JavaType b
436437
*
437438
* @return true if the class has type resolver annotations, false otherwise
438439
*
439-
* @since 2.15
440+
* @since 2.15, using {@code ai.findPolymorphicTypeInfo(config, ac)} since 2.16.
440441
*/
441442
protected boolean _hasTypeResolver(DeserializationConfig config, JavaType baseType) {
442443
AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, baseType.getRawClass());
443444
AnnotationIntrospector ai = config.getAnnotationIntrospector();
444-
return ai.findTypeResolver(config, ac, baseType) != null;
445+
return ai.findPolymorphicTypeInfo(config, ac) != null;
445446
}
446447
}

0 commit comments

Comments
 (0)