[jira] [Updated] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated SANDBOX-501: --- Attachment: commons-beanutils2.2015-11-15.patch ... and more tinkering. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.2015-11-15.patch, > commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15006027#comment-15006027 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 8:59 PM: -- ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. was (Author: mattmann): ... and more tinkering. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.2015-11-15.patch, > commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15006027#comment-15006027 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 9:01 PM: -- ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} package org.apache.commons.beanutils2.converters; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import org.apache.commons.beanutils2.Address; import org.apache.commons.beanutils2.ConverterRegistry; import org.apache.commons.beanutils2.State; import org.junit.Before; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import static java.lang.String.format; import static org.apache.commons.beanutils2.utils.StringUtils.length; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new)) .register(FunctionConverter.from(String.class).to(char.class).using(string -> { if (length(string) != 1) { throw new IllegalArgumentException(string); } return string.charAt(0); })); } @Test public void convert_StringToAddressArray() { final String source = "[ \"1600 Pennsylvania Avenue Northwest, Washington, DC 20500\", \"11 Wall Street, New York, NY 10005, US\", \"350 Fifth Avenue, New York, NY 10118\", \"4059 Mt Lee Drive, Hollywood, CA 90068\"]"; assertTrue(converter.canConvert(String.class, Address[].class)); final Address[] addresses = converter.convert(source, Address[].class, converterRegistry); assertEquals(4, addresses.length); assertEquals("1600 Pennsylvania Avenue Northwest", addresses[0].getStreetAddress()); assertEquals("Washington", addresses[0].getCity()); assertEquals(State.DC, addresses[0].getStateCode()); assertEquals("20500", addresses[0].getPostalCode()); assertNull(addresses[0].getCountryCode()); assertEquals("11 Wall Street", addresses[1].getStreetAddress()); assertEquals("New York", addresses[1].getCity()); assertEquals(State.NY, addresses[1].getStateCode()); assertEquals("10005", addresses[1].getPostalCode()); assertEquals("US", addresses[1].getCountryCode()); assertEquals("350 Fifth Avenue", addresses[2].getStreetAddress()); assertEquals("New York", addresses[2].getCity()); assertEquals(State.NY, addresses[2].getStateCode()); assertEquals("10118", addresses[2].getPostalCode()); assertNull(addresses[2].getCountryCode()); assertEquals("4059 Mt Lee Drive", addresses[3].getStreetAddress()); assertEquals("Hollywood", addresses[3].getCity()); assertEquals(State.CA, addresses[3].getStateCode()); assertEquals("90068", addresses[3].getPostalCode()); assertNull(addresses[3].getCountryCode()); } @Test public void convert_StringToNumberArray() { final BigDecimal a = BigDecimal.valueOf(Double.MAX_VALUE).pow(2); final BigInteger b = BigInteger.valueOf(Long.MAX_VALUE).pow(2); final int c = Integer.MAX_VALUE; final long d = Long.MAX_VALUE; final double e = Double.MAX_VALUE; final float f = Float.MAX_VALUE; final String source =
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15006027#comment-15006027 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 9:03 PM: -- ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new)) .register(FunctionConverter.from(String.class).to(char.class).using(string -> { if (length(string) != 1) { throw new IllegalArgumentException(string); } return string.charAt(0); })); } @Test public void convert_StringToAddressArray() { final String source = "[ \"1600 Pennsylvania Avenue Northwest, Washington, DC 20500\", \"11 Wall Street, New York, NY 10005, US\", \"350 Fifth Avenue, New York, NY 10118\", \"4059 Mt Lee Drive, Hollywood, CA 90068\"]"; assertTrue(converter.canConvert(String.class, Address[].class)); final Address[] addresses = converter.convert(source, Address[].class, converterRegistry); assertEquals(4, addresses.length); assertEquals("1600 Pennsylvania Avenue Northwest", addresses[0].getStreetAddress()); assertEquals("Washington", addresses[0].getCity()); assertEquals(State.DC, addresses[0].getStateCode()); assertEquals("20500", addresses[0].getPostalCode()); assertNull(addresses[0].getCountryCode()); assertEquals("11 Wall Street", addresses[1].getStreetAddress()); assertEquals("New York", addresses[1].getCity()); assertEquals(State.NY, addresses[1].getStateCode()); assertEquals("10005", addresses[1].getPostalCode()); assertEquals("US", addresses[1].getCountryCode()); assertEquals("350 Fifth Avenue", addresses[2].getStreetAddress()); assertEquals("New York", addresses[2].getCity()); assertEquals(State.NY, addresses[2].getStateCode()); assertEquals("10118", addresses[2].getPostalCode()); assertNull(addresses[2].getCountryCode()); assertEquals("4059 Mt Lee Drive", addresses[3].getStreetAddress()); assertEquals("Hollywood", addresses[3].getCity()); assertEquals(State.CA, addresses[3].getStateCode()); assertEquals("90068", addresses[3].getPostalCode()); assertNull(addresses[3].getCountryCode()); } ... } {code} was (Author: mattmann): ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new))
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15006027#comment-15006027 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 9:03 PM: -- ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new)) .register(FunctionConverter.from(String.class).to(char.class).using(string -> { if (length(string) != 1) { throw new IllegalArgumentException(string); } return string.charAt(0); })); } @Test public void convert_StringToAddressArray() { final String source = "[ \"1600 Pennsylvania Avenue Northwest, Washington, DC 20500\", \"11 Wall Street, New York, NY 10005, US\", \"350 Fifth Avenue, New York, NY 10118\", \"4059 Mt Lee Drive, Hollywood, CA 90068\"]"; assertTrue(converter.canConvert(String.class, Address[].class)); final Address[] addresses = converter.convert(source, Address[].class, converterRegistry); assertEquals(4, addresses.length); assertEquals("1600 Pennsylvania Avenue Northwest", addresses[0].getStreetAddress()); assertEquals("Washington", addresses[0].getCity()); assertEquals(State.DC, addresses[0].getStateCode()); assertEquals("20500", addresses[0].getPostalCode()); assertNull(addresses[0].getCountryCode()); assertEquals("11 Wall Street", addresses[1].getStreetAddress()); assertEquals("New York", addresses[1].getCity()); assertEquals(State.NY, addresses[1].getStateCode()); assertEquals("10005", addresses[1].getPostalCode()); assertEquals("US", addresses[1].getCountryCode()); assertEquals("350 Fifth Avenue", addresses[2].getStreetAddress()); assertEquals("New York", addresses[2].getCity()); assertEquals(State.NY, addresses[2].getStateCode()); assertEquals("10118", addresses[2].getPostalCode()); assertNull(addresses[2].getCountryCode()); assertEquals("4059 Mt Lee Drive", addresses[3].getStreetAddress()); assertEquals("Hollywood", addresses[3].getCity()); assertEquals(State.CA, addresses[3].getStateCode()); assertEquals("90068", addresses[3].getPostalCode()); assertNull(addresses[3].getCountryCode()); } ... } {code} was (Author: mattmann): ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} package org.apache.commons.beanutils2.converters; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import org.apache.commons.beanutils2.Address; import org.apache.commons.beanutils2.ConverterRegistry; import org.apache.commons.beanutils2.State; import org.junit.Before; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import static java.lang.String.format; import static org.apache.commons.beanutils2.utils.StringUtils.length; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry()
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15006027#comment-15006027 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 9:04 PM: -- ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new)) .register(FunctionConverter.from(String.class).to(char.class).using(string -> { if (length(string) != 1) { throw new IllegalArgumentException(string); } return string.charAt(0); })); } @Test public void convert_StringToAddressArray() { final String source = "[ \"1600 Pennsylvania Avenue Northwest, Washington, DC 20500\", \"11 Wall Street, New York, NY 10005, US\", \"350 Fifth Avenue, New York, NY 10118\", \"4059 Mt Lee Drive, Hollywood, CA 90068\"]"; assertTrue(converter.canConvert(String.class, Address[].class)); final Address[] addresses = converter.convert(source, Address[].class, converterRegistry); assertEquals(4, addresses.length); assertEquals("1600 Pennsylvania Avenue Northwest", addresses[0].getStreetAddress()); assertEquals("Washington", addresses[0].getCity()); assertEquals(State.DC, addresses[0].getStateCode()); assertEquals("20500", addresses[0].getPostalCode()); assertNull(addresses[0].getCountryCode()); assertEquals("11 Wall Street", addresses[1].getStreetAddress()); assertEquals("New York", addresses[1].getCity()); assertEquals(State.NY, addresses[1].getStateCode()); assertEquals("10005", addresses[1].getPostalCode()); assertEquals("US", addresses[1].getCountryCode()); assertEquals("350 Fifth Avenue", addresses[2].getStreetAddress()); assertEquals("New York", addresses[2].getCity()); assertEquals(State.NY, addresses[2].getStateCode()); assertEquals("10118", addresses[2].getPostalCode()); assertNull(addresses[2].getCountryCode()); assertEquals("4059 Mt Lee Drive", addresses[3].getStreetAddress()); assertEquals("Hollywood", addresses[3].getCity()); assertEquals(State.CA, addresses[3].getStateCode()); assertEquals("90068", addresses[3].getPostalCode()); assertNull(addresses[3].getCountryCode()); } ... } {code} was (Author: mattmann): ... and more tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772417/commons-beanutils2.2015-11-15.patch]. {code} public class StringToArrayTest { private StringToArray converter; private ConverterRegistry converterRegistry; @Before public void setUp() { converter = new StringToArray(); converterRegistry = new ConverterRegistry() .register(converter) .register(new JsonNumberConverter()) .register(new JsonStringConverter()) .register(new JsonArrayToArray()) .register(BigDecimal::toBigIntegerExact) .register(Address::parse) .register(FunctionConverter.from(BigDecimal.class).to(double.class).using(BigDecimal::doubleValue)) .register(FunctionConverter.from(BigDecimal.class).to(int.class).using(BigDecimal::intValueExact)) .register(FunctionConverter.from(String.class).to(BigDecimal.class).using(BigDecimal::new)) .register(FunctionConverter.from(String.class).to(char.class).using(string -> { if (length(string) != 1) { throw new IllegalArgumentException(string); } return string.charAt(0); })); } @Test public void convert_StringToAddressArray() { final String
[jira] [Commented] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15005507#comment-15005507 ] Matthew P Mann commented on SANDBOX-501: Benedikt, I think you're probably focused on commons-collections being vulnerable to remote code execution at the moment, but I was wondering if we might have a dialogue concerning commons-beanutils2 in the somewhat near future. Maybe a chat so we can have a back and forth in real time? I think we can start with the many areas upon which we agree and seeing about committing those changes without further ado. I'd also like to explore a way to provide optional support for Java 8 features without actually requiring Java 8. This might be accomplished by grouping the Java 8 stuff in an optional child artifact. I'm also wondering if we might adopt a [service loader mechanism|http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html] to register the default converters. I'm currently reviewing the [org.apache.commons.beanutils.converters|http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/converters/package-summary.html] and will see about adding to beanutils2. Regards, Matt > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Issue Comment Deleted] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated SANDBOX-501: --- Comment: was deleted (was: More tinkering. See attached patch.) > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Updated] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated SANDBOX-501: --- Attachment: commons-beanutils2.2015-11-14.patch More tinkering. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15005685#comment-15005685 ] Matthew P Mann edited comment on SANDBOX-501 at 11/15/15 12:41 AM: --- More tinkering. See [attached patch|https://issues.apache.org/jira/secure/attachment/12772396/commons-beanutils2.2015-11-14.patch]. was (Author: mattmann): More tinkering. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15005684#comment-15005684 ] Matthew P Mann commented on SANDBOX-501: More tinkering. See attached patch. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.2015-11-14.patch, commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15005133#comment-15005133 ] Matthew P Mann commented on SANDBOX-501: Some more tinkering today. Attaching a new patch. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Comment Edited] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15005133#comment-15005133 ] Matthew P Mann edited comment on SANDBOX-501 at 11/14/15 3:34 AM: -- Some more tinkering today. Attaching a new patch. was (Author: mattmann): Some more tinkering today. Attaching a new patch. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Updated] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated SANDBOX-501: --- Attachment: commons-beanutils2.2015-11-13.patch > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.2015-11-13.patch, > commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion.
[ https://issues.apache.org/jira/browse/BEANUTILS-481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14995720#comment-14995720 ] Matthew P Mann commented on BEANUTILS-481: -- Benedikt, The projects for which I wanted to use beanutils2 are not compatible with Java 8. I think there's probably a way to use lambda expressions with beanutils2 without the project itself being 1.8. Perhaps that could be accomplished by a supplementary project with conveniences for Java 1.8 features. For example: {code} transformerRegistry.register(new FunctionTransformer<>(Integer::parseInt, String.class, Integer.class)) {code} ... where FunctionTransformer would reside in the supplementary project. Incidentally, it's unfortunate that the source and target types cannot be inferred from a method literal like {{Integer::parseInt}}. And that reminds me: I don't think we should be assuming that a transformer/converter has only one source type and one target type. The performance of the lookup suffers, but I think a {{boolean canConvert(Object, Class)}} method is better than {{getSourceType()}} and {{getTargetType()}}. For example, I might want to be able to convert any enum to a string and vice versa using an instance of a single class. One more thing: Why are we calling the converter interface {{Transformer}} when it's principal method is {{convert}}? I'd either rename the class to {{Converter}} or (second choice) rename the method to {{transform}}. -Matt > [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.conversion-only.patch, > 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(" d, "); > 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(""); > 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-") > .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)
[jira] [Commented] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14995805#comment-14995805 ] Matthew P Mann commented on SANDBOX-501: Also, I'm not sure if you've seen my [previous comments|https://issues.apache.org/jira/browse/BEANUTILS-481?focusedCommentId=14995720=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14995720]. > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Updated] (SANDBOX-501) Add configurable type conversion support
[ https://issues.apache.org/jira/browse/SANDBOX-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated SANDBOX-501: --- Attachment: commons-beanutils2.java8.patch Benedikt, What do you think of this patch? {code} @Test public void test() throws MalformedURLException, ParseException { final DateFormat dateFormat = new SimpleDateFormat(" d, "); final BeanUtils beanUtils = BeanUtils .builder() .withDefaultTransformers() .withTransformer(MethodTransformer.from(String.class).to(Date.class).using(dateFormat, "parse")) .withTransformer(FunctionTransformer.from(String.class).to(PhoneNumber.class).using(PhoneNumber::parse)) .withTransformer(FunctionTransformer.from(String.class).to(State.class).using(State::valueOf)) .build(); final PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setAreaCode("202"); phoneNumber.setPrefix("456"); phoneNumber.setLineNumber(""); final Address address = new Address(); address.setStreetAddress("1600 Pennsylvania Avenue Northwest"); address.setCity("Washington"); address.setStateCode(State.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, beanUtils .bean(new Person()) .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-") .set("address").with( beanUtils .bean(new Address()) .set("streetAddress").with("1600 Pennsylvania Avenue Northwest") .set("city").with("Washington") .set("stateCode").with("DC") .set("postalCode").with(20500) .set("countryCode").with("US") .get() ) .get() ); } {code} -Matt > Add configurable type conversion support > > > Key: SANDBOX-501 > URL: https://issues.apache.org/jira/browse/SANDBOX-501 > Project: Commons Sandbox > Issue Type: New Feature > Components: BeanUtils2 >Reporter: Benedikt Ritter > Attachments: commons-beanutils2.java8.patch > > > BeanUtils1 supports automatic type conversion when setting properties. This > should be added to BeanUtils2. > A problem of the implementation of BeanUtils1 is, that the registry of > converts is cached in the BeanUtils class. BeanUtils2 should provide an API > for creating new instances of the o.a.c.beanutils2.BeanUtils with a > customized typ conversion registry. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion.
[ https://issues.apache.org/jira/browse/BEANUTILS-481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14988626#comment-14988626 ] Matthew P Mann commented on BEANUTILS-481: -- {code} public class AutoConversionTest { @Test public void test() throws MalformedURLException, ParseException { final DateFormat dateFormat = new SimpleDateFormat(" d, "); final PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setAreaCode("202"); phoneNumber.setPrefix("456"); phoneNumber.setLineNumber(""); 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()) .register(new StringToDate(dateFormat)) .register(new StringToPhoneNumber()) .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-") .set("address").with( on(new Address()) .register(new StringToState()) .set("streetAddress").with("1600 Pennsylvania Avenue Northwest") .set("city").with("Washington") .set("stateCode").with("DC") .set("postalCode").with(20500) .set("countryCode").with("US") .get() ) .get()); } } {code} > [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.conversion-only.patch, > 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(" d, "); > 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(""); > 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-") >
[jira] [Commented] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion.
[ https://issues.apache.org/jira/browse/BEANUTILS-481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14988616#comment-14988616 ] Matthew P Mann commented on BEANUTILS-481: -- Benedikt, See the attached commons-beanutils2.conversion-only.patch. There is a default transformer registry which is cloned if additional transformers/converters are registered. We would, of course, want to beef up the variety of default converters. I'd consider using commons-convert, but I have a problem with the core interface. https://commons.apache.org/sandbox/commons-convert/apidocs/org/apache/commons/convert/Converter.html If a converter can potentially support multiple source/target pairings (as suggested by the canConvert(...) method), how could it have a single sourceClass and a single targetClass (as suggested by getSourceClass() and getTargetClass())? -Matt > [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.conversion-only.patch, > 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(" d, "); > 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(""); > 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-") > .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)
[jira] [Updated] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion.
[ https://issues.apache.org/jira/browse/BEANUTILS-481?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Matthew P Mann updated BEANUTILS-481: - Attachment: commons-beanutils2.conversion-only.patch > [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.conversion-only.patch, > 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(" d, "); > 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(""); > 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-") > .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)
[jira] [Created] (BEANUTILS-481) [beanutils2] Support for nested properties and automatic conversion.
Matthew P Mann created BEANUTILS-481: Summary: [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 -- This message was sent by Atlassian JIRA (v6.3.4#6332)