full support for formatters on array/collection elements (SPR-6504)

This commit is contained in:
Juergen Hoeller
2009-12-04 00:34:40 +00:00
parent 388edd7aaa
commit e161c93f8d
6 changed files with 97 additions and 25 deletions

View File

@@ -53,11 +53,12 @@ class BeanTypeDescriptor extends TypeDescriptor {
/**
* Create a new BeanTypeDescriptor for the given bean property.
* @param methodParameter the target method parameter
* @param propertyDescriptor the corresponding JavaBean PropertyDescriptor
* @param methodParameter the target method parameter
* @param type the specific type to expose (may be an array/collection element)
*/
public BeanTypeDescriptor(MethodParameter methodParameter, PropertyDescriptor propertyDescriptor) {
super(methodParameter);
public BeanTypeDescriptor(PropertyDescriptor propertyDescriptor, MethodParameter methodParameter, Class type) {
super(methodParameter, type);
this.propertyDescriptor = propertyDescriptor;
}

View File

@@ -354,13 +354,15 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
try {
PropertyDescriptor pd = getPropertyDescriptorInternal(propertyName);
String canonicalName = PropertyAccessorUtils.getPropertyName(propertyName);
PropertyDescriptor pd = getPropertyDescriptorInternal(canonicalName);
if (pd != null) {
Class type = getPropertyType(propertyName);
if (pd.getReadMethod() != null) {
return new BeanTypeDescriptor(new MethodParameter(pd.getReadMethod(), -1), pd);
return new BeanTypeDescriptor(pd, new MethodParameter(pd.getReadMethod(), -1), type);
}
else if (pd.getWriteMethod() != null) {
return new BeanTypeDescriptor(BeanUtils.getWriteMethodParameter(pd), pd);
return new BeanTypeDescriptor(pd, BeanUtils.getWriteMethodParameter(pd), type);
}
}
}
@@ -579,7 +581,8 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
}
}
catch (Exception ex) {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name, "Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path: " + ex);
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,
"Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path: " + ex);
}
}