Skip to content

Commit dca1e3d

Browse files
committed
Replace use of commons-beanutils with Spring BeanWrapper
Signed-off-by: Roy Clarkson <roy.clarkson@broadcom.com>
1 parent e90d02c commit dca1e3d

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
buildscript {
1818
ext {
19-
// External Dependencies
20-
beanUtilsVersion = "1.11.0"
21-
2219
// Test Dependencies
2320
springCloudContractVersion = "5.0.2"
2421
equalsVerifierVersion = "4.4.2"

spring-cloud-open-service-broker-core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ dependencies {
3434
api 'io.projectreactor:reactor-core'
3535
api 'tools.jackson.core:jackson-databind'
3636
api 'org.hibernate.validator:hibernate-validator'
37-
api "commons-beanutils:commons-beanutils:${beanUtilsVersion}"
3837
api 'org.slf4j:slf4j-api'
3938
testImplementation 'org.springframework:spring-test'
4039
testImplementation 'io.projectreactor:reactor-test'

spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/model/instance/AsyncParameterizedServiceInstanceRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public Map<String, Object> getParameters() {
112112
* @param <T> the type of the object to instantiate and populate
113113
* @return the instantiated and populated object
114114
*/
115+
@SuppressWarnings("deprecation")
115116
public <T> T getParameters(Class<T> cls) {
116117
return ParameterBeanMapperUtils.mapParametersToBean(this.parameters, cls);
117118
}

spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/model/util/ParameterBeanMapperUtils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
import java.lang.reflect.InvocationTargetException;
2020
import java.util.Map;
2121

22-
import org.apache.commons.beanutils.BeanUtilsBean;
23-
import org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector;
22+
import org.springframework.beans.BeanWrapper;
23+
import org.springframework.beans.BeanWrapperImpl;
24+
import org.springframework.beans.BeansException;
25+
import org.springframework.beans.MutablePropertyValues;
2426

2527
/**
2628
* Utilities for mapping parameter maps to Java beans.
2729
*
2830
* @author Scott Frederick
31+
* @deprecated since 5.0.0 in favor of using Spring's {@link BeanWrapper} directly
2932
*/
33+
@Deprecated(since = "5.0.0")
3034
public final class ParameterBeanMapperUtils {
3135

3236
private ParameterBeanMapperUtils() {
@@ -45,13 +49,13 @@ public static <T> T mapParametersToBean(Map<String, Object> parameters, Class<T>
4549
try {
4650
T bean = cls.getDeclaredConstructor().newInstance();
4751

48-
BeanUtilsBean beanUtils = new BeanUtilsBean();
49-
beanUtils.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
50-
beanUtils.populate(bean, parameters);
52+
BeanWrapper wrapper = new BeanWrapperImpl(bean);
53+
wrapper.setPropertyValues(new MutablePropertyValues(parameters), true);
5154

5255
return bean;
5356
}
54-
catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
57+
catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException
58+
| BeansException ex) {
5559
throw new IllegalArgumentException("Error mapping parameters to class of type " + cls.getName(), ex);
5660
}
5761
}

spring-cloud-open-service-broker-core/src/test/java/org/springframework/cloud/servicebroker/model/util/ParameterBeanMapperUtilsTests.java

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
class ParameterBeanMapperUtilsTests {
2727

2828
@Test
29+
@SuppressWarnings("deprecation")
2930
void mapParametersToBean() {
3031
Map<String, Object> parameters = new HashMap<>();
3132
parameters.put("stringProperty", "value1");

0 commit comments

Comments
 (0)