You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Yang Diddy <io...@gmail.com> on 2014/03/27 05:38:08 UTC
[beanutils]how can I use BeanUtils.populate to set value to my property with diff-argument type between setter and getter?
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);
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [beanutils]how can I use BeanUtils.populate to set value to my
property with diff-argument type between setter and getter?
Posted by Oliver Heger <ol...@oliver-heger.de>.
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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org