-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning processAn outdated, unresolved issue that's closed in bulk as part of a cleaning process
Description
Fried Hoeben opened SPR-9482 and commented
When accessing bean properties via a BeanWrapper Boolean properties whose getter method uses an 'is' prefix rather than a 'get' prefix are not seen as readable.
If the type of the property is boolean (i.e. primitive) it is readable.
Please also allow reading of Boolean properties using the 'is' prefix.
As a workaround we created our own getValue() implementation, but that is not really what we would like:
private static Object getValue(BeanWrapper wrapper, String propertyName) {
Object result = null;
if (wrapper.isReadableProperty(propertyName)) {
result = wrapper.getPropertyValue(propertyName);
} else {
PropertyDescriptor propertyDescriptor = wrapper.getPropertyDescriptor(propertyName);
Class<?> propertyType = propertyDescriptor.getPropertyType();
if (Boolean.class.equals(propertyType)) {
String name = StringUtils.capitalize(propertyName);
Object expected = wrapper.getWrappedInstance();
Method m = ReflectionUtils.findMethod(expected.getClass(), "is" + name);
if (m != null && m.getReturnType().equals(Boolean.class)) {
result = ReflectionUtils.invokeMethod(m, expected);
} else {
throw new IllegalArgumentException(createErrorMsg(wrapper, propertyName));
}
} else {
throw new IllegalArgumentException(createErrorMsg(wrapper, propertyName));
}
}
return result;
}
private static String createErrorMsg(BeanWrapper wrapper, String propertyName) {
return propertyName + " can not be read on: " + wrapper.getWrappedClass();
}
Affects: 3.1.1
Attachments:
- IsPropertyTest.java (3.33 kB)
1 votes, 1 watchers
macjohnny
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning processAn outdated, unresolved issue that's closed in bulk as part of a cleaning process