java - can beanutil get the property of one field with its native type -
hi: using beanutil properties of bean,then put them map. found getproperty() can return string value,i wonder if can return native(original) type?
for example:
bean:
public class entity {  private string  name;  private int   age;  private list<date> childs = new arraylist<date>();   public entity(string name, int age, list<date> childs) {   this.name = name;   this.age = age;   this.childs = childs;  }   public static entity newinstance() {   list<date> list = new arraylist<date>();   list.add(new date());   list.add(new date());   return new entity("beanutil", 23, list);  }  //the getter , setter fields } then want field property of it,and not know fields requried,so use way:  public class beanutilmain {  public static void main(string[] args){   string[] requestpro={"name","childs"}; //this field specified clien   map<string, object> map=new hashmap<string, object>();   entity en=entity.newinstance();   for(string p:requestpro){    map.put(p, beanutils.getproperty(en, p));   }   system.out.println(map);  } } then map is:
{name=beanutil, childs=wed dec 01 12:24:37 cst 2010} the type of "childs" field java.util.list,but in example, converted java.lang.string.
i have hold orignal type of fields in map.
any ideas?
you can use propertyutils.getproperty(object, string) accomplish this.  returns value of field no type conversion.
Comments
Post a Comment