Re: [beanutils]how can I use BeanUtils.populate to set value to my property with diff-argument type between setter and getter?

2014-03-29 Thread Oliver Heger


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();
 MapString,Object values = new HashMapString,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-unsubscr...@commons.apache.org
 For additional commands, e-mail: user-h...@commons.apache.org
 

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



[beanutils]how can I use BeanUtils.populate to set value to my property with diff-argument type between setter and getter?

2014-03-26 Thread 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();
MapString,Object values = new HashMapString,Object();
values.put(“id”,”1000”);
BeanUtils.populate(foo, values);
logger.debug(foo);
-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org