Skip to content

Commit

Permalink
Refactoring to simplify complexity of type resolution for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 19, 2016
1 parent 25a3b5b commit 6231c4d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
Expand Up @@ -74,15 +74,19 @@ protected BeanDescription(JavaType type) {
* types of member object, such as return and argument types of
* methods and constructors, and types of fields.
*
* @deprecated Since 2.7, use {@link #resolveType(java.lang.reflect.Type)} instead.
* @deprecated Since 2.7, should not need to access bindings directly
*/
@Deprecated
public abstract TypeBindings bindingsForBeanType();

/**
* Method for resolving given JDK type, using this bean as the
* generic type resolution context.
*
* @deprecated Since 2.8, should simply call <code>getType</code> of
* property accessor directly.
*/
@Deprecated
public abstract JavaType resolveType(java.lang.reflect.Type jdkType);

/**
Expand Down
Expand Up @@ -837,16 +837,11 @@ protected SettableBeanProperty constructCreatorProperty(DeserializationContext c
metadata = PropertyMetadata.construct(req, desc, idx, def);
}
}
// 15-Oct-2015, tatu: Not 100% if context needed; removing it does not make any
// existing unit tests fail. Still seems like the right thing to do.
JavaType t0 = beanDesc.resolveType(param.getParameterType());
BeanProperty.Std property = new BeanProperty.Std(name, t0,
JavaType t0 = param.getType();
JavaType type = resolveTypeOverrides(ctxt, t0, param);
BeanProperty.Std property = new BeanProperty.Std(name, type,
intr.findWrapperName(param),
beanDesc.getClassAnnotations(), param, metadata);
JavaType type = resolveType(ctxt, beanDesc, t0, param);
if (type != t0) {
property = property.withType(type);
}
// Is there an annotation that specifies exact deserializer?
JsonDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, param);

Expand All @@ -865,7 +860,7 @@ protected SettableBeanProperty constructCreatorProperty(DeserializationContext c
typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId,
metadata);
if (deser != null) {
// As per [Issue#462] need to ensure we contextualize deserializer before passing it on
// As per [databind#462] need to ensure we contextualize deserializer before passing it on
deser = ctxt.handlePrimaryContextualization(deser, prop, type);
prop = prop.withValueDeserializer(deser);
}
Expand Down Expand Up @@ -1856,14 +1851,15 @@ protected <T extends JavaType> T modifyTypeByAnnotation(DeserializationContext c
}

/**
* Helper method used to resolve method return types and field
* types. The main trick here is that the containing bean may
* have type variable binding information (when deserializing
* using generic type passed as type reference), which is
* needed in some cases.
* Helper method used to resolve additional type-related annotation information
* like type overrides, or handler (serializer, deserializer) overrides,
* so that from declared field, property or constructor parameter type
* is used as the base and modified based on annotations, if any.
*
* @since 2.8 Renamed in 2.8, used to be called <code>resolveType</code>
*/
protected JavaType resolveType(DeserializationContext ctxt,
BeanDescription beanDesc, JavaType type, AnnotatedMember member)
protected JavaType resolveTypeOverrides(DeserializationContext ctxt,
JavaType type, AnnotatedMember member)
throws JsonMappingException
{
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
Expand Down Expand Up @@ -1918,7 +1914,18 @@ protected JavaType resolveType(DeserializationContext ctxt,
}
return type;
}


/**
* @deprecated since 2.8 call {@link #resolveTypeOverrides} instead.
*/
@Deprecated // since 2.8
protected JavaType resolveType(DeserializationContext ctxt,
BeanDescription beanDesc, JavaType type, AnnotatedMember member)
throws JsonMappingException
{
return resolveTypeOverrides(ctxt, type, member);
}

protected EnumResolver constructEnumResolver(Class<?> enumClass,
DeserializationConfig config, AnnotatedMethod jsonValueMethod)
{
Expand All @@ -1934,6 +1941,10 @@ protected EnumResolver constructEnumResolver(Class<?> enumClass,
return EnumResolver.constructUnsafe(enumClass, config.getAnnotationIntrospector());
}

/**
* @deprecated since 2.8 call <code>findJsonValueMethod</code> on {@link BeanDescription} instead
*/
@Deprecated // not used, possibly remove as early as 2.9
protected AnnotatedMethod _findJsonValueFor(DeserializationConfig config, JavaType enumType)
{
if (enumType == null) {
Expand Down
Expand Up @@ -697,7 +697,7 @@ protected SettableAnyProperty constructAnySetter(DeserializationContext ctxt,
BeanProperty.Std property = new BeanProperty.Std(PropertyName.construct(setter.getName()),
type, null, beanDesc.getClassAnnotations(), setter,
PropertyMetadata.STD_OPTIONAL);
type = resolveType(ctxt, beanDesc, type, setter);
type = resolveTypeOverrides(ctxt, type, setter);

/* AnySetter can be annotated with @JsonDeserialize (etc) just like a
* regular setter... so let's see if those are used.
Expand Down Expand Up @@ -738,7 +738,7 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
BeanProperty.Std property = new BeanProperty.Std(propDef.getFullName(),
propType0, propDef.getWrapperName(),
beanDesc.getClassAnnotations(), mutator, propDef.getMetadata());
JavaType type = resolveType(ctxt, beanDesc, propType0, mutator);
JavaType type = resolveTypeOverrides(ctxt, propType0, mutator);
// did type change?
if (type != propType0) {
property = property.withType(type);
Expand Down Expand Up @@ -790,8 +790,8 @@ protected SettableBeanProperty constructSetterlessProperty(DeserializationContex
// First: does the Method specify the deserializer to use? If so, let's use it.
JsonDeserializer<Object> propDeser = findDeserializerFromAnnotation(ctxt, getter);
type = modifyTypeByAnnotation(ctxt, getter, type);
// As per [Issue#501], need full resolution:
type = resolveType(ctxt, beanDesc, type, getter);
// As per [databind#501], need full resolution:
type = resolveTypeOverrides(ctxt, type, getter);
TypeDeserializer typeDeser = type.getTypeHandler();
SettableBeanProperty prop = new SetterlessProperty(propDef, type, typeDeser,
beanDesc.getClassAnnotations(), getter);
Expand Down
Expand Up @@ -252,6 +252,7 @@ public TypeBindings bindingsForBeanType() {
}

@Override
@Deprecated // since 2.8
public JavaType resolveType(java.lang.reflect.Type jdkType) {
if (jdkType == null) {
return null;
Expand Down

0 comments on commit 6231c4d

Please sign in to comment.