Java Code Examples for org.apache.commons.beanutils.BeanUtilsBean#copyProperties()

The following examples show how to use org.apache.commons.beanutils.BeanUtilsBean#copyProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationBeanUtils.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
public static <T> void populate(T targetObject, Map<String, Object> properties) {
	if (properties == null) {
		return;
	}

	T target = getTargetObject(targetObject);

	try {
		BeanUtilsBean beanUtils = new BeanUtilsBean();
		beanUtils.getPropertyUtils().addBeanIntrospector(DefaultBeanIntrospector.INSTANCE);
		beanUtils.getPropertyUtils().addBeanIntrospector(new KebabCasePropertyBeanIntrospector());
		beanUtils.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
		beanUtils.copyProperties(target, properties);
	}
	catch (IllegalAccessException | InvocationTargetException e) {
		throw new IllegalArgumentException("Failed to populate target of type " + targetObject.getClass()
			+ " with properties " + properties, e);
	}
}
 
Example 2
Source File: BeanUtils.java    From cola-cloud with MIT License 5 votes vote down vote up
private static void copyProperties(Object from,Object to,BeanUtilsBean bub){
    try {
        bub.copyProperties(to,from);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: CommonsExample.java    From pragmatic-java-engineer with GNU General Public License v3.0 5 votes vote down vote up
public static void beanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
    BeanUtilsBean beanUtilsBean = new BeanUtilsBean2();
    beanUtilsBean.getConvertUtils().register(false, false, 0);//错误不抛出异常、不使用Null做默认值,数组的默认大小为0

    User user = new User();
    user.setName("test");
    TestUser testUser = new TestUser();

    beanUtilsBean.copyProperties(testUser, user);
    System.out.println(testUser);
}