From 0f96945ae1e9b5a4334677932b28c8cf709825ef Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Wed, 28 Aug 2024 19:54:59 +0200 Subject: [PATCH 1/4] [BEANUTILS-565] merge BeanUtilsBean2, ConvertUtilsBean2 up --- .../commons/beanutils2/BeanUtilsBean.java | 16 +- .../commons/beanutils2/BeanUtilsBean2.java | 75 ------- .../commons/beanutils2/ConvertUtilsBean.java | 75 ++----- .../commons/beanutils2/ConvertUtilsBean2.java | 77 ------- .../beanutils2/BeanUtilsBean2TestCase.java | 192 ------------------ .../beanutils2/BeanUtilsBeanTestCase.java | 19 +- 6 files changed, 28 insertions(+), 426 deletions(-) delete mode 100644 src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java delete mode 100644 src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java delete mode 100644 src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java index 9b81b2aa0..b7a333cc1 100644 --- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java @@ -33,7 +33,8 @@ import org.apache.commons.logging.LogFactory; /** - *

JavaBean property population methods.

+ *

JavaBean property population methods, delegating + * conversions to {@link ConvertUtilsBean#convert(Object, Class)}.

* *

This class provides implementations for the utility methods in * {@link BeanUtils}. @@ -214,23 +215,12 @@ public Object cloneBean(final Object bean) *

Converts the value to an object of the specified class (if * possible).

* - * @param The desired return type * @param value Value to be converted (may be null) * @param type Class of the value to be converted to * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - * @since 1.8.0 */ protected Object convert(final Object value, final Class type) { - final Converter converter = getConvertUtils().lookup(type); - if (converter != null) { - if (LOG.isTraceEnabled()) { - LOG.trace(" USING CONVERTER " + converter); - } - return converter.convert(type, value); - } - return value; + return getConvertUtils().convert(value, type); } /** diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java b/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java deleted file mode 100644 index bf6ba35e6..000000000 --- a/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -/** - *

{@link BeanUtilsBean} implementation that creates a - * {@link ConvertUtilsBean2} and delegates conversion to - * {@link ConvertUtilsBean#convert(Object, Class)}. - *

- * - *

- * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - *

- * - *

- * BeanUtils 1.7.0 delegated all conversion to String to the converter - * registered for the {@code String.class}. One of the improvements in - * BeanUtils 1.8.0 was to upgrade the {@link Converter} implementations so - * that they could handle conversion to String for their type (e.g. - * IntegerConverter now handles conversion from an Integer to a String as - * well as String to Integer). - *

- * - *

- * In order to take advantage of these improvements BeanUtils needs to change - * how it gets the appropriate {@link Converter}. This functionality has been - * implemented in the new {@link ConvertUtilsBean#lookup(Class, Class)} and - * {@link ConvertUtilsBean#convert(Object, Class)} methods. However changing - * {@link BeanUtilsBean} to use these methods could create compatibility - * issues for existing users. In order to avoid that, this new - * {@link BeanUtilsBean} implementation has been created (and the associated - * {@link ConvertUtilsBean2}). - *

- * - * @see ConvertUtilsBean2 - * @since 1.8.0 - */ -public class BeanUtilsBean2 extends BeanUtilsBean { - - /** - *

Constructs an instance using new property - * and conversion instances.

- */ - public BeanUtilsBean2() { - super(new ConvertUtilsBean2()); - } - - /** - *

Converts the value to an object of the specified class (if - * possible).

- * - * @param value Value to be converted (may be null) - * @param type Class of the value to be converted to - * @return The converted value - */ - @Override - protected Object convert(final Object value, final Class type) { - return getConvertUtils().convert(value, type); - } -} diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java index 590bdfafc..8750f2eda 100644 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java @@ -145,6 +145,7 @@ *
  • java.time.ZoneId (no default value)
  • *
  • java.time.ZoneOffset (no default value)
  • * + *

    Every other convert method will be delegated to {@link ConvertUtilsBean#convert(Object, Class)}.

    * *

    For backwards compatibility, the standard Converters for primitive * types (and the corresponding wrapper classes) return a defined @@ -220,35 +221,16 @@ public ConvertUtilsBean() { } /** - * Convert the specified value into a String. If the specified value - * is an array, the first element (converted to a String) will be - * returned. The registered {@link Converter} for the - * {@link String} class will be used, which allows - * applications to customize Object->String conversions (the default - * implementation simply uses toString()). + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null + * + * @see ConvertUtilsBean#convert(String[], Class) */ public String convert(Object value) { - - if (value == null) { - return null; - } - if (!value.getClass().isArray()) { - final Converter converter = lookup(String.class); - return converter.convert(String.class, value); - } - if (Array.getLength(value) < 1) { - return null; - } - value = Array.get(value, 0); - if (value == null) { - return null; - } - final Converter converter = lookup(String.class); - return converter.convert(String.class, value); - + return (String) convert(value, String.class); } /** @@ -307,58 +289,31 @@ public Object convert(final Object value, final Class targetType) { } /** - * Convert the specified value to an object of the specified class (if - * possible). Otherwise, return a {@link String} representation of the value. + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * - * @param The desired return type * @param value Value to be converted (may be null) * @param clazz Java class to be converted to (must not be null) - * @return The converted value + * @return The converted value or null if value is null * - * @throws ConversionException if thrown by an underlying Converter + * @see ConvertUtilsBean#convert(String[], Class) */ public Object convert(final String value, final Class clazz) { - if (LOG.isDebugEnabled()) { - LOG.debug("Convert string '" + value + "' to class '" + clazz.getName() + "'"); - } - final Converter converter = lookup(clazz); - if (converter == null) { - final Converter sConverter = lookup(String.class); - if (LOG.isTraceEnabled()) { - LOG.trace(" Using converter " + converter); - } - return sConverter.convert(String.class, value); - } - if (LOG.isTraceEnabled()) { - LOG.trace(" Using converter " + converter); - } - return converter.convert(clazz, value); + return convert((Object) value, clazz); } /** - * Convert an array of specified values to an array of objects of the - * specified class (if possible). If the specified Java class is itself - * an array class, this class will be the type of the returned value. - * Otherwise, an array will be constructed whose component type is the - * specified class. + * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} + * method. * - * @param The Class type. * @param values Array of values to be converted * @param clazz Java array or element class to be converted to (must not be null) * @return The converted value * - * @throws ConversionException if thrown by an underlying Converter + * @see ConvertUtilsBean#convert(String[], Class) */ public Object convert(final String[] values, final Class clazz) { - final Class type = clazz.isArray() ? clazz.getComponentType() : clazz; - if (LOG.isDebugEnabled()) { - LOG.debug("Convert String[" + values.length + "] to class '" + type.getName() + "[]'"); - } - Converter converter = lookup(type); - if (converter == null) { - converter = lookup(String.class); - } - return convert(values, type, converter); + return convert((Object) values, clazz); } private Object convert(final String[] values, final Class type, final Converter converter) { diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java deleted file mode 100644 index e268d49c2..000000000 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -/** - * {@link ConvertUtilsBean} implementation that delegates {@code convert()} - * methods to the new {@link ConvertUtilsBean#convert(Object, Class)} method. - * - *

    - * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - *

    - * - * @see BeanUtilsBean2 - * @since 1.8.0 - */ -public class ConvertUtilsBean2 extends ConvertUtilsBean { - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @return The converted String value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public String convert(final Object value) { - return (String) convert(value, String.class); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @param clazz Java class to be converted to (must not be null) - * @return The converted value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public Object convert(final String value, final Class clazz) { - return convert((Object) value, clazz); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Array of values to be converted - * @param clazz Java array or element class to be converted to (must not be null) - * @return The converted value - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public Object convert(final String[] value, final Class clazz) { - return convert((Object) value, clazz); - } - -} diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java deleted file mode 100644 index 6ab032aa2..000000000 --- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBean2TestCase.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.beanutils2; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Test Case for the {@link BeanUtilsBean2}. - */ -public class BeanUtilsBean2TestCase extends BeanUtilsBeanTestCase { - - /** - * Creates the tests included in this test suite. - */ - public static Test suite() { - return new TestSuite(BeanUtilsBean2TestCase.class); - } - - /** - * Constructs a new instance of this test case. - * - * @param name Name of the test case - */ - public BeanUtilsBean2TestCase(final String name) { - super(name); - } - - /** - * Sets up instance variables required by this test case. - */ - @Override - public void setUp() { - ConvertUtils.deregister(); - BeanUtilsBean.setInstance(new BeanUtilsBean2()); - setUpShared(); - } - - /** - * Tear down instance variables required by this test case. - */ - @Override - public void tearDown() { - bean = null; - } - - /** - * Test {@code copyProperty()} converting to a String. - */ - @Override - public void testCopyPropertyConvertToString() { - try { - BeanUtils.copyProperty(bean, "stringProperty", testUtilDate); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty()); - } - - /** - * Test {@code copyProperty()} converting to a String. - */ - @Override - public void testCopyPropertyConvertToStringArray() { - try { - bean.setStringArray(null); - BeanUtils.copyProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); - assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); - } - - /** - * Test {@code copyProperty()} converting to a String on indexed property - */ - @Override - public void testCopyPropertyConvertToStringIndexed() { - try { - bean.setStringArray(new String[1]); - BeanUtils.copyProperty(bean, "stringArray[0]", testUtilDate); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); - assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); - } - - /** - * Test {@code getArrayProperty()} converting to a String. - */ - @Override - public void testGetArrayPropertyDate() { - String[] value = null; - try { - bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); - value = BeanUtils.getArrayProperty(bean, "dateArrayProperty"); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date[] --> String[] length", 1, value.length); - assertEquals("java.util.Date[] --> String[] value ", testStringDate, value[0]); - } - - /** - * Test {@code getArrayProperty()} converting to a String. - */ - @Override - public void testGetIndexedPropertyDate() { - String value = null; - try { - bean.setDateArrayProperty(new java.util.Date[] { testUtilDate }); - value = BeanUtils.getIndexedProperty(bean, "dateArrayProperty[0]"); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date[0] --> String", testStringDate, value); - } - - /** - * Test {@code getSimpleProperty()} converting to a String. - */ - @Override - public void testGetSimplePropertyDate() { - String value = null; - try { - bean.setDateProperty(testUtilDate); - value = BeanUtils.getSimpleProperty(bean, "dateProperty"); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date --> String", testStringDate, value); - } - - /** - * Test {@code setProperty()} converting to a String. - */ - @Override - public void testSetPropertyConvertToString() { - try { - BeanUtils.setProperty(bean, "stringProperty", testUtilDate); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty()); - } - - /** - * Test {@code setProperty()} converting to a String array. - */ - @Override - public void testSetPropertyConvertToStringArray() { - try { - bean.setStringArray(null); - BeanUtils.setProperty(bean, "stringArray", new java.util.Date[] { testUtilDate }); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); - assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); - } - - /** - * Test {@code setProperty()} converting to a String on indexed property - */ - @Override - public void testSetPropertyConvertToStringIndexed() { - try { - bean.setStringArray(new String[1]); - BeanUtils.setProperty(bean, "stringArray[0]", testUtilDate); - } catch (final Throwable t) { - fail("Threw " + t); - } - assertEquals("java.util.Date --> String[]", testStringDate, bean.getStringArray()[0]); - } - -} diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java index 4374fc352..1e0be6a30 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java @@ -413,7 +413,7 @@ public void testCopyPropertyConvertToString() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date --> String", testUtilDate.toString(), bean.getStringProperty()); + assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty()); } /** @@ -427,7 +427,7 @@ public void testCopyPropertyConvertToStringArray() { fail("Threw " + t); } assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); - assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), bean.getStringArray()[0]); + assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); } /** @@ -440,7 +440,8 @@ public void testCopyPropertyConvertToStringIndexed() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date --> String[]", testUtilDate.toString(), bean.getStringArray()[0]); + assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); + assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); } /** @@ -733,7 +734,7 @@ public void testGetArrayPropertyDate() { fail("Threw " + t); } assertEquals("java.util.Date[] --> String[] length", 1, value.length); - assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), value[0]); + assertEquals("java.util.Date[] --> String[] value ", testStringDate, value[0]); } /** @@ -810,7 +811,7 @@ public void testGetIndexedPropertyDate() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date[0] --> String", testUtilDate.toString(), value); + assertEquals("java.util.Date[0] --> String", testStringDate, value); } public void testGetMappedProperty2Args() throws Exception { @@ -871,7 +872,7 @@ public void testGetSimplePropertyDate() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date --> String", testUtilDate.toString(), value); + assertEquals("java.util.Date --> String", testStringDate, value); } /** @@ -1207,7 +1208,7 @@ public void testSetPropertyConvertToString() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date --> String", testUtilDate.toString(), bean.getStringProperty()); + assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty()); } /** @@ -1221,7 +1222,7 @@ public void testSetPropertyConvertToStringArray() { fail("Threw " + t); } assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length); - assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), bean.getStringArray()[0]); + assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]); } /** @@ -1234,7 +1235,7 @@ public void testSetPropertyConvertToStringIndexed() { } catch (final Throwable t) { fail("Threw " + t); } - assertEquals("java.util.Date --> String[]", testUtilDate.toString(), bean.getStringArray()[0]); + assertEquals("java.util.Date --> String[]", testStringDate, bean.getStringArray()[0]); } /** From d83720bed3a74ef38d2e9fbd5dbecd6a2b47c311 Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Thu, 29 Aug 2024 08:21:25 +0200 Subject: [PATCH 2/4] [BEANUTILS-565] revert method `public Object convert(final String[] values, final Class clazz)` --- .../apache/commons/beanutils2/ConvertUtilsBean.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java index 8750f2eda..1c54e5e44 100644 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java @@ -313,7 +313,15 @@ public Object convert(final String value, final Class clazz) { * @see ConvertUtilsBean#convert(String[], Class) */ public Object convert(final String[] values, final Class clazz) { - return convert((Object) values, clazz); + final Class type = clazz.isArray() ? clazz.getComponentType() : clazz; + if (LOG.isDebugEnabled()) { + LOG.debug("Convert String[" + values.length + "] to class '" + type.getName() + "[]'"); + } + Converter converter = lookup(type); + if (converter == null) { + converter = lookup(String.class); + } + return convert(values, type, converter); } private Object convert(final String[] values, final Class type, final Converter converter) { From 3f3dac2116573fdd11b9ec2a6fb4e7ef8f872a9d Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Thu, 29 Aug 2024 08:27:02 +0200 Subject: [PATCH 3/4] [BEANUTILS-565] revert method `public String convert(Object value)` --- .../commons/beanutils2/ConvertUtilsBean.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java index 1c54e5e44..9b094efd0 100644 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java @@ -221,16 +221,35 @@ public ConvertUtilsBean() { } /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. + * Convert the specified value into a String. If the specified value + * is an array, the first element (converted to a String) will be + * returned. The registered {@link Converter} for the + * {@link String} class will be used, which allows + * applications to customize Object->String conversions (the default + * implementation simply uses toString()). * * @param value Value to be converted (may be null) * @return The converted String value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) */ public String convert(Object value) { - return (String) convert(value, String.class); + + if (value == null) { + return null; + } + if (!value.getClass().isArray()) { + final Converter converter = lookup(String.class); + return converter.convert(String.class, value); + } + if (Array.getLength(value) < 1) { + return null; + } + value = Array.get(value, 0); + if (value == null) { + return null; + } + final Converter converter = lookup(String.class); + return converter.convert(String.class, value); + } /** From 7662e35d479125de2a43ff280f03db7a0d130443 Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Thu, 29 Aug 2024 08:29:12 +0200 Subject: [PATCH 4/4] [BEANUTILS-565] revert method `public Object convert(final String[] values, final Class clazz)` javadoc --- .../apache/commons/beanutils2/ConvertUtilsBean.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java index 9b094efd0..193c1ecdd 100644 --- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java @@ -322,14 +322,18 @@ public Object convert(final String value, final Class clazz) { } /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. + * Convert an array of specified values to an array of objects of the + * specified class (if possible). If the specified Java class is itself + * an array class, this class will be the type of the returned value. + * Otherwise, an array will be constructed whose component type is the + * specified class. * + * @param The Class type. * @param values Array of values to be converted * @param clazz Java array or element class to be converted to (must not be null) * @return The converted value * - * @see ConvertUtilsBean#convert(String[], Class) + * @throws ConversionException if thrown by an underlying Converter */ public Object convert(final String[] values, final Class clazz) { final Class type = clazz.isArray() ? clazz.getComponentType() : clazz;