Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 66762 invoked from network); 2 Dec 2010 16:40:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Dec 2010 16:40:38 -0000 Received: (qmail 91056 invoked by uid 500); 2 Dec 2010 16:40:37 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 90749 invoked by uid 500); 2 Dec 2010 16:40:35 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 90741 invoked by uid 99); 2 Dec 2010 16:40:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Dec 2010 16:40:34 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of brent.worden@gmail.com designates 209.85.161.43 as permitted sender) Received: from [209.85.161.43] (HELO mail-fx0-f43.google.com) (209.85.161.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Dec 2010 16:40:27 +0000 Received: by fxm6 with SMTP id 6so5391206fxm.30 for ; Thu, 02 Dec 2010 08:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=NAhPKri8vzyuP5oJ6ZBmIgZ0oD+wZbmjr0SrofdtvpE=; b=Y//DhEY7PBpydqSxGZqxJI+Im+N8F/fs3WkK84VwHVtIfL1x1QNnNW/wzgZdb+EMvS 8HPpiEOX1m03M6QDVYgjXKNrPqRnLFhVv38GoBvOjGU05OAWDlTG/J3rSZT6vBJFRYAd YrPiAWieRbqv460tIg7XxsQN3J7yQGKv4DDco= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=OlLgGFccv0HVv3gRIz/OeS65Wr7e1RqyXZDkeFw0pZ5Bz+5Hbi+PIIdvfMBuesqi81 OTUqEZymvm3bqMslnYmOiGEtgUAFXC237IFTFjKl1Q9aoQX1bWlZFsVCqtl7sCa9XQ3f 55BDYuNsvKcX8ZpQFFE7bbTAMOC0az6AThjSc= MIME-Version: 1.0 Received: by 10.223.116.69 with SMTP id l5mr805854faq.129.1291308006923; Thu, 02 Dec 2010 08:40:06 -0800 (PST) Received: by 10.223.118.207 with HTTP; Thu, 2 Dec 2010 08:40:06 -0800 (PST) In-Reply-To: References: Date: Thu, 2 Dec 2010 10:40:06 -0600 Message-ID: Subject: Re: can beanutil get the property of one field with its native type From: Brent Worden To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org I think you are just observing ArrayList's toString behavior. BeanUtils.getProperty() returns the same object that the corresponding getter method returns. Try replacing System.out.println(map) with something like System.out.println(map.get("childs").getClass().getName()) to see what the actual object type is. HTH, Brent. On Tue, Nov 30, 2010 at 10:53 PM, maven apache wro= te: > Hi: I am using BeanUtil to get the properties of some bean,then put them = to > map. However I found that the getProperty() can only return the string > value,I wonder if it can return the native(original) type? > > For example: > Bean: > > public class Entity { > =A0private String =A0name; > =A0private int =A0 age; > =A0private List childs =3D new ArrayList(); > > =A0public Entity(String name, int age, List childs) { > =A0this.name =3D name; > =A0this.age =3D age; > =A0this.childs =3D childs; > =A0} > > =A0public static Entity newInstance() { > =A0List list =3D new ArrayList(); > =A0list.add(new Date()); > =A0list.add(new Date()); > =A0return new Entity("Beanutil", 23, list); > =A0} > =A0//the getter and setter for all the fields } > > ------------------------------ > > Then I want to get some field property of it,and I do not exactly know > which fields are requried,so I use it this way: > =A0public class BeanUtilMain { > =A0public static void main(String[] args){ > =A0String[] requestPro=3D{"name","childs"}; //this field is specified by = clien > =A0Map map=3Dnew HashMap(); > =A0Entity en=3DEntity.newInstance(); > =A0for(String p:requestPro){ > =A0 map.put(p, BeanUtils.getProperty(en, p)); > =A0} > =A0System.out.println(map); > =A0} } > > Then the map is: > > {name=3Dbeanutil, childs=3DWed Dec 01 12:24:37 CST 2010} > > The type of "childs" field is java.util.List,but in the example, it is > converted to java.lang.String. > > I have to hold the orignal type of the fields in the map. > > Any ideas? > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org