perform narrowing in reflective property accessor read methods as well

This commit is contained in:
Keith Donald 2011-06-05 06:01:48 +00:00
parent c306afed63
commit 9ece4a88a9
1 changed files with 6 additions and 4 deletions

View File

@ -138,7 +138,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (method != null) { if (method != null) {
try { try {
ReflectionUtils.makeAccessible(method); ReflectionUtils.makeAccessible(method);
return new TypedValue(method.invoke(target),invoker.typeDescriptor); Object value = method.invoke(target);
return new TypedValue(value, invoker.typeDescriptor.narrow(value));
} }
catch (Exception ex) { catch (Exception ex) {
throw new AccessException("Unable to access property '" + name + "' through getter", ex); throw new AccessException("Unable to access property '" + name + "' through getter", ex);
@ -147,7 +148,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
} }
if (invoker == null || invoker.member instanceof Field) { if (invoker == null || invoker.member instanceof Field) {
Field field = (Field) (invoker==null?null:invoker.member); Field field = (Field) (invoker == null ? null : invoker.member);
if (field == null) { if (field == null) {
field = findField(name, type, target instanceof Class); field = findField(name, type, target instanceof Class);
if (field != null) { if (field != null) {
@ -158,7 +159,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (field != null) { if (field != null) {
try { try {
ReflectionUtils.makeAccessible(field); ReflectionUtils.makeAccessible(field);
return new TypedValue(field.get(target),invoker.typeDescriptor); Object value = field.get(target);
return new TypedValue(value, invoker.typeDescriptor.narrow(value));
} }
catch (Exception ex) { catch (Exception ex) {
throw new AccessException("Unable to access field: " + name, ex); throw new AccessException("Unable to access field: " + name, ex);
@ -183,7 +185,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
// Treat it like a property // Treat it like a property
PropertyDescriptor propertyDescriptor = null; PropertyDescriptor propertyDescriptor = null;
try { try {
propertyDescriptor = new PropertyDescriptor(name,null,method); propertyDescriptor = new PropertyDescriptor(name, null, method);
} }
catch (IntrospectionException ex) { catch (IntrospectionException ex) {
throw new AccessException("Unable to access property '" + name + "' through setter "+method, ex); throw new AccessException("Unable to access property '" + name + "' through setter "+method, ex);