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 27D9A187F1 for ; Sun, 1 Nov 2015 10:21:28 +0000 (UTC) Received: (qmail 67739 invoked by uid 500); 1 Nov 2015 10:21:27 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 67651 invoked by uid 500); 1 Nov 2015 10:21:27 -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 67628 invoked by uid 99); 1 Nov 2015 10:21:27 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Nov 2015 10:21:27 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id B07D92C1F51 for ; Sun, 1 Nov 2015 10:21:27 +0000 (UTC) Date: Sun, 1 Nov 2015 10:21:27 +0000 (UTC) From: "Benedikt Ritter (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/BEANUTILS-481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14984330#comment-14984330 ] Benedikt Ritter commented on BEANUTILS-481: ------------------------------------------- Hello Matthew, thank you for the patch! Since it mixes to changes (automatic conversion and nested properties) it's hard for me to review. Is it possible to split this up into two separate patches? Regarding nested properties: We already have the PropertyInterpreter, which is capable of parsing those. But we we were not fond whether nested properties fit into the design of BeanUtils2 at all. It feels redundant because we have the fluent API for traversing an object graph. Regarding automatic conversion: This is a feature we definitely need. However a was thinking about a slightly different approach. The BeanUtils class should hold a default transformer registry with all sorts of commons transformer implementations. When you call BeanUtils.on(...) you're working with this instance. However you should be able to use your own transformer registry or derive it from the existing one. With Java 8 lambdas, it may make sense to pull BeanUtils2 up to Java 8 to be able to define transformers in a concise way. > [beanutils2] Support for nested properties and automatic conversion. > -------------------------------------------------------------------- > > Key: BEANUTILS-481 > URL: https://issues.apache.org/jira/browse/BEANUTILS-481 > Project: Commons BeanUtils > Issue Type: Improvement > Reporter: Matthew P Mann > Fix For: 2.0 > > Attachments: commons-beanutils2.patch > > > Please consider the attached patch for the commons-beanutils2 project. I added support for nested properties and automatic conversion. Excerpt from AutoConversionTest: > {code} > final DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy"); > final TransformerRegistry transformerRegistry = new TransformerRegistry() > .register(new StringToDate(dateFormat)) > .register(new IntegerToString()) > .register(new StringToColor()) > .register(new IntegerToColor()) > .register(new StringToURL()) > .register(new StringToPhoneNumber()); > final PhoneNumber phoneNumber = new PhoneNumber(); > phoneNumber.setAreaCode("202"); > phoneNumber.setPrefix("456"); > phoneNumber.setLineNumber("1111"); > final Address address = new Address(); > address.setStreetAddress("1600 Pennsylvania Avenue Northwest"); > address.setCity("Washington"); > address.setStateCode("DC"); > address.setPostalCode("20500"); > address.setCountryCode("US"); > final Person person = new Person(); > person.setFirstName("Barack"); > person.setLastName("Obama"); > person.setBirthDate(dateFormat.parse("August 4, 1961")); > person.setEyeColor(Color.decode("#362819")); > person.setHairColor(GRAY); > person.setPhoneNumber(phoneNumber); > person.setAddress(address); > person.setWebsite(new URL("https://www.barackobama.com/")); > assertEquals(person, on(new Person(), transformerRegistry) > .set("firstName").with("Barack") > .set("lastName").with("Obama") > .set("birthDate").with("August 4, 1961") > .set("hairColor").with(0x808080) > .set("eyeColor").with("#362819") > .set("website").with("https://www.barackobama.com/") > .set("phoneNumber").with("202-456-1111") > .set("address").with(new Address()) > .set("address.streetAddress").with("1600 Pennsylvania Avenue Northwest") > .set("address.city").with("Washington") > .set("address.stateCode").with("DC") > .set("address.postalCode").with(20500) > .set("address.countryCode").with("US") > .get()); > {code} > Thanks, > Matt -- This message was sent by Atlassian JIRA (v6.3.4#6332)