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..193c1ecdd 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
@@ -307,32 +308,17 @@ 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);
}
/**
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]);
}
/**