Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 39046 invoked from network); 21 Dec 2002 19:33:29 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 21 Dec 2002 19:33:29 -0000 Received: (qmail 22670 invoked by uid 97); 21 Dec 2002 19:34:42 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 22632 invoked by uid 97); 21 Dec 2002 19:34:41 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 22621 invoked by uid 97); 21 Dec 2002 19:34:40 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 21 Dec 2002 19:33:21 -0000 Message-ID: <20021221193321.32207.qmail@icarus.apache.org> From: craigmcc@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils BeanUtilsTestCase.java DynaBeanUtilsTestCase.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N craigmcc 2002/12/21 11:33:20 Modified: beanutils/src/java/org/apache/commons/beanutils BeanUtils.java beanutils/src/test/org/apache/commons/beanutils BeanUtilsTestCase.java DynaBeanUtilsTestCase.java Log: Enhance the behavior of BeanUtils.setProperty() such that, if the destination property is a String and there is a registered Converter for the value's class, the value's toString() method will be called, followed by conversion to the appropriate destination type. Among other things, this makes it possible to pass in a primitive wrapper type (such as Integer) and have it converted to a String. PR: Bugzilla #15170 Submitted by: Runako Godfrey Revision Changes Path 1.32 +6 -4 jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java Index: BeanUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtils.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- BeanUtils.java 16 Dec 2002 01:31:29 -0000 1.31 +++ BeanUtils.java 21 Dec 2002 19:33:19 -0000 1.32 @@ -905,6 +905,8 @@ } else if (value instanceof String[]) { newValue = ConvertUtils.convert(((String[]) value)[0], type); + } else if (ConvertUtils.lookup(value.getClass()) != null) { + newValue = ConvertUtils.convert(value.toString(), type); } else { newValue = value; } 1.16 +14 -6 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java Index: BeanUtilsTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- BeanUtilsTestCase.java 9 Dec 2002 22:17:12 -0000 1.15 +++ BeanUtilsTestCase.java 21 Dec 2002 19:33:20 -0000 1.16 @@ -782,10 +782,18 @@ } - /** See http://issues.apache.org/bugzilla/show_bug.cgi?id=15170 */ - public void testSetPropertyOnPrimitavieWrappers() throws Exception { + /** + * Test converting to and from primitive wrapper types. + */ + public void testSetPropertyOnPrimitiveWrappers() throws Exception { + BeanUtils.setProperty(bean,"intProperty", new Integer(1)); assertEquals(1,bean.getIntProperty()); + BeanUtils.setProperty(bean,"stringProperty", new Integer(1)); + assertEquals(1, Integer.parseInt(bean.getStringProperty())); + } + + } 1.13 +17 -4 jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java Index: DynaBeanUtilsTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- DynaBeanUtilsTestCase.java 21 Jul 2002 00:20:45 -0000 1.12 +++ DynaBeanUtilsTestCase.java 21 Dec 2002 19:33:20 -0000 1.13 @@ -832,6 +832,19 @@ } + /** + * Test converting to and from primitive wrapper types. + */ + public void testSetPropertyOnPrimitiveWrappers() throws Exception { + + BeanUtils.setProperty(bean,"intProperty", new Integer(1)); + assertEquals(1,((Integer) bean.get("intProperty")).intValue()); + BeanUtils.setProperty(bean,"stringProperty", new Integer(1)); + assertEquals(1, Integer.parseInt((String) bean.get("stringProperty"))); + + } + + // ------------------------------------------------------ Protected Methods -- To unsubscribe, e-mail: For additional commands, e-mail: