Skip to content

Commit 7c6c6e2

Browse files
committed
Bit more clean up in 2.12 for #2846
1 parent da390a5 commit 7c6c6e2

File tree

5 files changed

+59
-38
lines changed

5 files changed

+59
-38
lines changed

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,9 @@ public static AnnotatedClass constructWithoutSuperTypes(Class<?> raw, MapperConf
226226

227227
@Override
228228
public JavaType resolveType(Type type) {
229-
// 05-Sep-2020, tatu: [databind#2846][databind#2821] avoid
230-
// passing context in case of Raw class (generic type declared
231-
// without type parametrers) as that can lead to mismatch
232-
if (type instanceof Class<?>) {
233-
return _typeFactory.constructType(type);
234-
}
235-
return _typeFactory.constructType(type, _bindings);
229+
// 06-Sep-2020, tatu: Careful wrt [databind#2846][databind#2821],
230+
// call new method added in 2.12
231+
return _typeFactory.resolveMemberType(type, _bindings);
236232
}
237233

238234
/*

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ public TypeBindings bindingsForBeanType() {
281281
@Override
282282
@Deprecated // since 2.8
283283
public JavaType resolveType(java.lang.reflect.Type jdkType) {
284-
if (jdkType == null) {
285-
return null;
286-
}
287-
return _config.getTypeFactory().constructType(jdkType, _type.getBindings());
284+
// 06-Sep-2020, tatu: Careful wrt [databind#2846][databind#2821],
285+
// call new method added in 2.12
286+
return _config.getTypeFactory().resolveMemberType(jdkType, _type.getBindings());
288287
}
289288

290289
@Override

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ public Basic(TypeFactory tf, TypeBindings b) {
2828

2929
@Override
3030
public JavaType resolveType(Type type) {
31-
// 15-Jun-2020, tatu: As a consequence of [databind#2796], need to
32-
// AVOID passing bindings for raw, type-erased cases, as otherwise
33-
// we seem to get odd "generic Long" cases (for Mr Bean module at least)
34-
if (type instanceof Class<?>) {
35-
return _typeFactory.constructType(type);
36-
}
37-
return _typeFactory.constructType(type, _bindings);
31+
// 06-Sep-2020, tatu: Careful wrt [databind#2846][databind#2821],
32+
// call new method added in 2.12
33+
return _typeFactory.resolveMemberType(type, _bindings);
3834
}
3935

4036
/*// debugging

src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java

+49-20
Original file line numberDiff line numberDiff line change
@@ -687,35 +687,17 @@ public JavaType moreSpecificType(JavaType type1, JavaType type2)
687687
}
688688
return type1;
689689
}
690-
690+
691691
/*
692692
/**********************************************************
693-
/* Public factory methods
693+
/* Public general-purpose factory methods
694694
/**********************************************************
695695
*/
696696

697697
public JavaType constructType(Type type) {
698698
return _fromAny(null, type, EMPTY_BINDINGS);
699699
}
700700

701-
/**
702-
* Method that you very likely should NOT be using -- you need to know a lot
703-
* about internal details of {@link TypeBindings} and even then it will probably
704-
* not do what you want.
705-
* Usually you would instead want to call one of {@code constructXxxType()}
706-
* methods (where {@code Xxx} would be "Array", "Collection[Like]", "Map[Like]"
707-
* or "Parametric").
708-
*/
709-
public JavaType constructType(Type type, TypeBindings bindings) {
710-
// 15-Jun-2020, tatu: To resolve (parts of) [databind#2796], need to
711-
// call _fromClass() directly if we get `Class` argument
712-
if (type instanceof Class<?>) {
713-
JavaType resultType = _fromClass(null, (Class<?>) type, bindings);
714-
return _applyModifiers(type, resultType);
715-
}
716-
return _fromAny(null, type, bindings);
717-
}
718-
719701
public JavaType constructType(TypeReference<?> typeRef)
720702
{
721703
// 19-Oct-2015, tatu: Simpler variant like so should work
@@ -740,6 +722,53 @@ public JavaType constructType(TypeReference<?> typeRef)
740722
*/
741723
}
742724

725+
/**
726+
* Method to call when resolving types of {@link java.lang.reflect.Member}s
727+
* like Fields, Methods and Constructor parameters and there is a
728+
* {@link TypeBindings} (that describes binding of type parameters within
729+
* context) to pass.
730+
* This is typically used only by code in databind itself.
731+
*
732+
* @param type Type of a {@link java.lang.reflect.Member} to resolve
733+
* @param bindings Type bindings from the context, often class in which
734+
* member declared but may be subtype of that type (to bind actual bound
735+
* type parametrers). Not used if {@code type} is of type {@code Class<?>}.
736+
*
737+
* @return Fully resolve type
738+
*
739+
* @since 2.12 as replacement for deprecated {@link #constructType(Type, TypeBindings)}
740+
*/
741+
public JavaType resolveMemberType(Type type, TypeBindings contextBindings) {
742+
return _fromAny(null, type, contextBindings);
743+
}
744+
745+
/*
746+
/**********************************************************
747+
/* Deprecated public factory methods
748+
/**********************************************************
749+
*/
750+
751+
/**
752+
* Method that you very likely should NOT be using -- you need to know a lot
753+
* about internal details of {@link TypeBindings} and even then it will probably
754+
* not do what you want.
755+
* Usually you would instead want to call one of {@code constructXxxType()}
756+
* methods (where {@code Xxx} would be "Array", "Collection[Like]", "Map[Like]"
757+
* or "Parametric").
758+
*
759+
* @deprecated Since 2.12
760+
*/
761+
@Deprecated // since 2.12
762+
public JavaType constructType(Type type, TypeBindings bindings) {
763+
// 15-Jun-2020, tatu: To resolve (parts of) [databind#2796], need to
764+
// call _fromClass() directly if we get `Class` argument
765+
if (type instanceof Class<?>) {
766+
JavaType resultType = _fromClass(null, (Class<?>) type, bindings);
767+
return _applyModifiers(type, resultType);
768+
}
769+
return _fromAny(null, type, bindings);
770+
}
771+
743772
/**
744773
* @deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
745774
*/

src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ public void testCollections()
322322
}
323323

324324
// [databind#2796]
325+
@SuppressWarnings("deprecation")
325326
public void testCollectionsWithBindings()
326327
{
327328
final TypeFactory tf = TypeFactory.defaultInstance();

0 commit comments

Comments
 (0)