Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 06A0D9A92 for ; Mon, 5 Mar 2012 03:43:28 +0000 (UTC) Received: (qmail 80921 invoked by uid 500); 5 Mar 2012 03:43:27 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 80753 invoked by uid 500); 5 Mar 2012 03:43:26 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 80713 invoked by uid 99); 5 Mar 2012 03:43:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 03:43:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Mar 2012 03:43:24 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 6FABC86BC for ; Mon, 5 Mar 2012 03:43:04 +0000 (UTC) Date: Mon, 5 Mar 2012 03:43:04 +0000 (UTC) From: "Senthil Kumar Balakrishnan (Commented) (JIRA)" To: issues@commons.apache.org Message-ID: <1279948841.21366.1330918984507.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <654528595.10575.1323863253888.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (BEANUTILS-409) BeanUtils - 'describe' method returning Incorrect array value MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/BEANUTILS-409?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1= 3222154#comment-13222154 ]=20 Senthil Kumar Balakrishnan commented on BEANUTILS-409: ------------------------------------------------------ Hi Benny, The Code is deliberately returning first value of the collection, though i = don't understand why it should. below is the code, org.apache.commons.beanutils.converters.AbstractConverter.java /** * Return the first element from an Array (or Collection) * or the value unchanged if not an Array (or Collection). * * N.B. This needs to be overriden for array/Collection converters. * * @param value The value to convert * @return The first element in an Array (or Collection) * or the value unchanged if not an Array (or Collection) */ protected Object convertArray(Object value) { if (value =3D=3D null) { return null; } if (value.getClass().isArray()) { if (Array.getLength(value) > 0) { return Array.get(value, 0); } else { return null; } } if (value instanceof Collection) { Collection collection =3D (Collection)value; if (collection.size() > 0) { =09=09//Note: Looks like this is done deliberately. return collection.iterator().next(); } else { return null; } } return value; } Thanks, -Senthil Balakrishnan =20 > BeanUtils - 'describe' method returning Incorrect array value > ------------------------------------------------------------- > > Key: BEANUTILS-409 > URL: https://issues.apache.org/jira/browse/BEANUTILS-409 > Project: Commons BeanUtils > Issue Type: Bug > Affects Versions: 1.8.3 > Environment: commons-beanutils 1.8.3, jdk 1.6.0_20 > Reporter: benny > Priority: Critical > Labels: describe > > I want to convert a bean class to a map (key=3Dthe name of the member,val= ue=3Dthe value of the member). > I'm using the method BeanUtils.describe(beanClass); > (I'm using commons-beanutils 1.8.3, jdk 1.6.0_20, on commons-beanutils 1.= 5 it works) > The problem is that the return value is incorrect, (the map contain only = the first item from the array), > the code: > public class Demo {=20 > private ArrayList myList =3D new ArrayList();=20 > public Demo() {=20 > myList.add("first_value");=20 > myList.add("second_value");=20 > }=20 > =20 > public ArrayList getMyList() {=20 > return myList;=20 > }=20 > =20 > public void setMyList(ArrayList myList) {=20 > this.myList =3D myList;=20 > }=20 > =20 > public static void main(String[] args) {=20 > Demo myBean =3D new Demo();=20 > try {=20 > Map describe =3D BeanUtils.describe(myBean);=20 > Iterator it =3D describe.entrySet().iterator();=20 > while (it.hasNext()) {=20 > Map.Entry pairs =3D (Map.Entry) it.next();=20 > System.out.println(String.format("key=3D%s,value=3D%s= ", (String) pairs.getKey(), (String) pairs.getValue()));=20 > =20 > }=20 > } catch (Exception e) {=20 > e.printStackTrace();=20 > }=20 > }=20 > }=20 > =E2=80=A2The expected output: > =20 > key=3DmyList,value=3D[first_value,second_value] > key=3Dclass,value=3Dclass $Demo > =E2=80=A2But the real output is: > =20 > key=3DmyList,value=3D[first_value] > key=3Dclass,value=3Dclass $Demo > As you can see the array contains two values but the output(and the map) = contains only one,why?? -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira