Am 27.03.2014 05:38, schrieb Yang Diddy:
> Please help:
> if property of my class's setter and setter method arguments type doesn’t
> match, how can i populate bean object?
>
> public class Foo extends SomeClass{
> private int id;
>
> @Override
> public Object getId() {
> return id;
> }
>
> public void setId(int id) {
> this.id = id;
> }
> }
>
> // testing
> Foo foot = new Foo();
> Map<String,Object> values = new HashMap<String,Object>();
> values.put(“id”,”1000”);
> BeanUtils.populate(foo, values);
> logger.debug(foo);
Per default, BeanUtils only supports classes complying to the Java Beans
specification. This is obviously not the case for your class.
>From version 1.9.x onwards, BeanUtils allows extending the introspection
facilities so that non-conform properties could be detected, too. This
is described in the user guide [1].
I am not sure whether this is an option for you because it requires some
effort to implement a custom BeanIntrospector just to add support for
these properties with incompatible argument types. But AFAIK, this is
the only way to make BeanUtils recognize them.
Oliver
[1]
http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.1/apidocs/org/apache/commons/beanutils/package-summary.html#standard.customize
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]