Skip to content

Commit

Permalink
Bit more clean up in 2.12 for #2846
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 6, 2020
1 parent da390a5 commit 7c6c6e2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,9 @@ public static AnnotatedClass constructWithoutSuperTypes(Class<?> raw, MapperConf

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

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ public TypeBindings bindingsForBeanType() {
@Override
@Deprecated // since 2.8
public JavaType resolveType(java.lang.reflect.Type jdkType) {
if (jdkType == null) {
return null;
}
return _config.getTypeFactory().constructType(jdkType, _type.getBindings());
// 06-Sep-2020, tatu: Careful wrt [databind#2846][databind#2821],
// call new method added in 2.12
return _config.getTypeFactory().resolveMemberType(jdkType, _type.getBindings());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ public Basic(TypeFactory tf, TypeBindings b) {

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

/*// debugging
Expand Down
69 changes: 49 additions & 20 deletions src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,35 +687,17 @@ public JavaType moreSpecificType(JavaType type1, JavaType type2)
}
return type1;
}

/*
/**********************************************************
/* Public factory methods
/* Public general-purpose factory methods
/**********************************************************
*/

public JavaType constructType(Type type) {
return _fromAny(null, type, EMPTY_BINDINGS);
}

/**
* Method that you very likely should NOT be using -- you need to know a lot
* about internal details of {@link TypeBindings} and even then it will probably
* not do what you want.
* Usually you would instead want to call one of {@code constructXxxType()}
* methods (where {@code Xxx} would be "Array", "Collection[Like]", "Map[Like]"
* or "Parametric").
*/
public JavaType constructType(Type type, TypeBindings bindings) {
// 15-Jun-2020, tatu: To resolve (parts of) [databind#2796], need to
// call _fromClass() directly if we get `Class` argument
if (type instanceof Class<?>) {
JavaType resultType = _fromClass(null, (Class<?>) type, bindings);
return _applyModifiers(type, resultType);
}
return _fromAny(null, type, bindings);
}

public JavaType constructType(TypeReference<?> typeRef)
{
// 19-Oct-2015, tatu: Simpler variant like so should work
Expand All @@ -740,6 +722,53 @@ public JavaType constructType(TypeReference<?> typeRef)
*/
}

/**
* Method to call when resolving types of {@link java.lang.reflect.Member}s
* like Fields, Methods and Constructor parameters and there is a
* {@link TypeBindings} (that describes binding of type parameters within
* context) to pass.
* This is typically used only by code in databind itself.
*
* @param type Type of a {@link java.lang.reflect.Member} to resolve
* @param bindings Type bindings from the context, often class in which
* member declared but may be subtype of that type (to bind actual bound
* type parametrers). Not used if {@code type} is of type {@code Class<?>}.
*
* @return Fully resolve type
*
* @since 2.12 as replacement for deprecated {@link #constructType(Type, TypeBindings)}
*/
public JavaType resolveMemberType(Type type, TypeBindings contextBindings) {
return _fromAny(null, type, contextBindings);
}

/*
/**********************************************************
/* Deprecated public factory methods
/**********************************************************
*/

/**
* Method that you very likely should NOT be using -- you need to know a lot
* about internal details of {@link TypeBindings} and even then it will probably
* not do what you want.
* Usually you would instead want to call one of {@code constructXxxType()}
* methods (where {@code Xxx} would be "Array", "Collection[Like]", "Map[Like]"
* or "Parametric").
*
* @deprecated Since 2.12
*/
@Deprecated // since 2.12
public JavaType constructType(Type type, TypeBindings bindings) {
// 15-Jun-2020, tatu: To resolve (parts of) [databind#2796], need to
// call _fromClass() directly if we get `Class` argument
if (type instanceof Class<?>) {
JavaType resultType = _fromClass(null, (Class<?>) type, bindings);
return _applyModifiers(type, resultType);
}
return _fromAny(null, type, bindings);
}

/**
* @deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public void testCollections()
}

// [databind#2796]
@SuppressWarnings("deprecation")
public void testCollectionsWithBindings()
{
final TypeFactory tf = TypeFactory.defaultInstance();
Expand Down

0 comments on commit 7c6c6e2

Please sign in to comment.