You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/24 18:42:20 UTC
[commons-beanutils] branch master updated: [BEANUTILS-515] Java8
Time converters (#14)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push:
new 11187b2 [BEANUTILS-515] Java8 Time converters (#14)
11187b2 is described below
commit 11187b2a6612bc8bf7081b43d45057170734df4a
Author: Melloware <me...@gmail.com>
AuthorDate: Thu Oct 24 14:42:10 2019 -0400
[BEANUTILS-515] Java8 Time converters (#14)
* [BEANUTILS-515] Java8 Time converters
* [BEANUTILS-515] Cleaned up Release Notes about Collections4 adding a remove type.
* [BEANUTILS-515] Cleaned up Release Notes about Collections4 adding a remove type.
* [BEANUTILS-515] Code Review fixed ConvertUtilsBean spacing.
* [BEANUTILS-515] Code Review close <p> tags
* [BEANUTILS-515] Code Review added @see tags.
---
src/changes/changes.xml | 15 +--
.../commons/beanutils2/ConvertUtilsBean.java | 127 +++++++++++++++++----
...teTimeConverter.java => DurationConverter.java} | 45 +++++---
.../beanutils2/converters/LocalDateConverter.java | 3 +
.../converters/LocalDateTimeConverter.java | 3 +
...lDateConverter.java => LocalTimeConverter.java} | 45 +++++---
...teTimeConverter.java => MonthDayConverter.java} | 45 +++++---
.../converters/OffsetDateTimeConverter.java | 3 +
...TimeConverter.java => OffsetTimeConverter.java} | 45 +++++---
...DateTimeConverter.java => PeriodConverter.java} | 45 +++++---
...etDateTimeConverter.java => YearConverter.java} | 45 +++++---
...lDateConverter.java => YearMonthConverter.java} | 45 +++++---
...DateTimeConverter.java => ZoneIdConverter.java} | 45 +++++---
...TimeConverter.java => ZoneOffsetConverter.java} | 45 +++++---
.../converters/ZonedDateTimeConverter.java | 3 +
.../converters/DurationConverterTestCase.java | 118 +++++++++++++++++++
.../converters/LocalTimeConverterTestCase.java | 116 +++++++++++++++++++
.../converters/MonthDayConverterTestCase.java | 118 +++++++++++++++++++
.../converters/OffsetTimeConverterTestCase.java | 116 +++++++++++++++++++
.../converters/PeriodConverterTestCase.java | 118 +++++++++++++++++++
.../converters/YearConverterTestCase.java | 118 +++++++++++++++++++
.../converters/YearMonthConverterTestCase.java | 118 +++++++++++++++++++
.../converters/ZoneIdConverterTestCase.java | 118 +++++++++++++++++++
.../converters/ZoneOffsetConverterTestCase.java | 118 +++++++++++++++++++
24 files changed, 1459 insertions(+), 158 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 99d899c..ad06a82 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -29,7 +29,7 @@
</properties>
<body>
- <release version="2.0.0" date="2018-MM-DD" description="Update from Java 6 to 7, update from Apache Commons Collection 3 to 4.">
+ <release version="2.0.0" date="2018-MM-DD" description="Update to Java 8.">
<action issue="BEANUTILS-402" dev="melloware" type="update" due-to="Melloware">
Double-Checked Locking anti pattern in WeakFastHashMap.
</action>
@@ -42,9 +42,6 @@
<action issue="BEANUTILS-503" dev="ggregory" type="update" due-to="Gary Gregory">
Change packaging from org.apache.commons.beanutils to org.apache.commons.beanutils2.
</action>
- <action issue="BEANUTILS-500" dev="dbrosius" type="update" due-to="Dave Brosius, Gary Gregory">
- Upgrade from Apache Commons Collections 3 to 4.
- </action>
<action issue="BEANUTILS-505" dev="ggregory" type="update" due-to="Gary Gregory">
Add missing serialVersionUID to Serializable classes.
</action>
@@ -57,9 +54,6 @@
<action issue="BEANUTILS-509" dev="ggregory" type="update" due-to="sunil, Akshay Gehi">
WeakHashmap enters into infinite loop in WrapDynaClass.java.
</action>
- <action issue="BEANUTILS-517" dev="ggregory" type="update" due-to="Gary Gregory">
- Update Apache Commons Collections from 4.2 to 4.3.
- </action>
<action issue="BEANUTILS-520" dev="ggregory" type="update" due-to="Melloware">
BeanUtils2 mitigate CVE-2014-0114.
</action>
@@ -67,13 +61,16 @@
Update Apache Commons Collections from 4.3 to 4.4.
</action>
<action issue="BEANUTILS-527" dev="ggregory" type="update" due-to="Melloware, Matt Sicker, Gary Gregory">
- Convert Collections4 to java.util.function #8.
+ Convert Collections4 to java.util.function. #8.
+ </action>
+ <action issue="BEANUTILS-527" dev="ggregory" type="remove" due-to="Melloware, Matt Sicker, Gary Gregory">
+ Removed Commons Collections dependency. #8.
</action>
<action issue="BEANUTILS-528" dev="ggregory" type="update" due-to="Melloware, Matt Sicker, Gary Gregory">
New converters for UUID, URI, and Path #10.
</action>
<action issue="BEANUTILS-515" dev="ggregory" type="update" due-to="Melloware, Matt Sicker, Gary Gregory">
- New converters for Java 8 Time classes LocalDate, LocaleDateTime, ZonedDateTime, OffsetDateTime #13.
+ New converters for Java 8 Time classes #13.
</action>
<action issue="BEANUTILS-529" dev="ggregory" type="update" due-to="Gary Gregory">
Log at the debug level instead of info.
diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
index 8197c6f..cd9d36b 100644
--- a/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
+++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
@@ -27,6 +27,19 @@ import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.sql.Timestamp;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.MonthDay;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.Period;
+import java.time.Year;
+import java.time.YearMonth;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Collection;
import java.util.UUID;
@@ -42,11 +55,19 @@ import org.apache.commons.beanutils2.converters.ClassConverter;
import org.apache.commons.beanutils2.converters.ConverterFacade;
import org.apache.commons.beanutils2.converters.DateConverter;
import org.apache.commons.beanutils2.converters.DoubleConverter;
+import org.apache.commons.beanutils2.converters.DurationConverter;
import org.apache.commons.beanutils2.converters.FileConverter;
import org.apache.commons.beanutils2.converters.FloatConverter;
import org.apache.commons.beanutils2.converters.IntegerConverter;
+import org.apache.commons.beanutils2.converters.LocalDateConverter;
+import org.apache.commons.beanutils2.converters.LocalDateTimeConverter;
+import org.apache.commons.beanutils2.converters.LocalTimeConverter;
import org.apache.commons.beanutils2.converters.LongConverter;
+import org.apache.commons.beanutils2.converters.MonthDayConverter;
+import org.apache.commons.beanutils2.converters.OffsetDateTimeConverter;
+import org.apache.commons.beanutils2.converters.OffsetTimeConverter;
import org.apache.commons.beanutils2.converters.PathConverter;
+import org.apache.commons.beanutils2.converters.PeriodConverter;
import org.apache.commons.beanutils2.converters.ShortConverter;
import org.apache.commons.beanutils2.converters.SqlDateConverter;
import org.apache.commons.beanutils2.converters.SqlTimeConverter;
@@ -55,6 +76,11 @@ import org.apache.commons.beanutils2.converters.StringConverter;
import org.apache.commons.beanutils2.converters.URIConverter;
import org.apache.commons.beanutils2.converters.URLConverter;
import org.apache.commons.beanutils2.converters.UUIDConverter;
+import org.apache.commons.beanutils2.converters.YearConverter;
+import org.apache.commons.beanutils2.converters.YearMonthConverter;
+import org.apache.commons.beanutils2.converters.ZoneIdConverter;
+import org.apache.commons.beanutils2.converters.ZoneOffsetConverter;
+import org.apache.commons.beanutils2.converters.ZonedDateTimeConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -87,6 +113,19 @@ import org.apache.commons.logging.LogFactory;
* <li>java.sql.Date (no default value)</li>
* <li>java.sql.Time (no default value)</li>
* <li>java.sql.Timestamp (no default value)</li>
+ * <li>java.time.LocalDate (no default value)</li>
+ * <li>java.time.LocalDateTime (no default value)</li>
+ * <li>java.time.LocalTime (no default value)</li>
+ * <li>java.time.OffsetDateTime (no default value)</li>
+ * <li>java.time.OffsetTime (no default value)</li>
+ * <li>java.time.ZonedDateTime (no default value)</li>
+ * <li>java.time.Duration (no default value)</li>
+ * <li>java.time.MonthDay (no default value)</li>
+ * <li>java.time.Period (no default value)</li>
+ * <li>java.time.Year (no default value)</li>
+ * <li>java.time.YearMonth (no default value)</li>
+ * <li>java.time.ZoneId (no default value)</li>
+ * <li>java.time.ZoneOffset (no default value)</li>
* </ul>
*
* <p>For backwards compatibility, the standard Converters for primitive
@@ -460,23 +499,51 @@ public class ConvertUtilsBean {
* <li><code>URL.class</code> - {@link URLConverter}</li>
* <li><code>URI.class</code> - {@link URIConverter}</li>
* <li><code>UUID.class</code> - {@link UUIDConverter}</li>
+ * <li><code>LocalDate.class</code> - {@link LocalDateConverter}</li>
+ * <li><code>LocalDateTime.class</code> - {@link LocalDateTimeConverter}</li>
+ * <li><code>LocalTime.class</code> - {@link LocalTimeConverter}</li>
+ * <li><code>OffsetDateTime.class</code> - {@link OffsetDateTimeConverter}</li>
+ * <li><code>OffsetTime.class</code> - {@link OffsetTimeConverter}</li>
+ * <li><code>ZonedDateTime.class</code> - {@link ZonedDateTimeConverter}</li>
+ * <li><code>Duration.class</code> - {@link DurationConverter}</li>
+ * <li><code>MonthDay.class</code> - {@link MonthDayConverter}</li>
+ * <li><code>Period.class</code> - {@link PeriodConverter}</li>
+ * <li><code>Year.class</code> - {@link YearConverter}</li>
+ * <li><code>YearMonth.class</code> - {@link YearMonthConverter}</li>
+ * <li><code>ZoneId.class</code> - {@link ZoneIdConverter}</li>
+ * <li><code>ZoneOffset.class</code> - {@link ZoneOffsetConverter}</li>
* </ul>
* @param throwException <code>true</code> if the converters should
* throw an exception when a conversion error occurs, otherwise <code>
* <code>false</code> if a default value should be used.
*/
private void registerOther(final boolean throwException) {
- register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null));
- register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null));
- register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null));
- register(File.class, throwException ? new FileConverter() : new FileConverter(null));
- register(Path.class, throwException ? new PathConverter() : new PathConverter(null));
- register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null));
- register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null));
- register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null));
- register(URL.class, throwException ? new URLConverter() : new URLConverter(null));
- register(URI.class, throwException ? new URIConverter() : new URIConverter(null));
- register(UUID.class, throwException ? new UUIDConverter() : new UUIDConverter(null));
+ // @formatter:off
+ register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null));
+ register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null));
+ register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null));
+ register(File.class, throwException ? new FileConverter() : new FileConverter(null));
+ register(Path.class, throwException ? new PathConverter() : new PathConverter(null));
+ register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null));
+ register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null));
+ register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null));
+ register(URL.class, throwException ? new URLConverter() : new URLConverter(null));
+ register(URI.class, throwException ? new URIConverter() : new URIConverter(null));
+ register(UUID.class, throwException ? new UUIDConverter() : new UUIDConverter(null));
+ register(LocalDate.class, throwException ? new LocalDateConverter() : new LocalDateConverter(null));
+ register(LocalDateTime.class, throwException ? new LocalDateTimeConverter() : new LocalDateTimeConverter(null));
+ register(LocalTime.class, throwException ? new LocalTimeConverter() : new LocalTimeConverter(null));
+ register(OffsetDateTime.class, throwException ? new OffsetDateTimeConverter() : new OffsetDateTimeConverter(null));
+ register(OffsetTime.class, throwException ? new OffsetTimeConverter() : new OffsetTimeConverter(null));
+ register(ZonedDateTime.class, throwException ? new ZonedDateTimeConverter() : new ZonedDateTimeConverter(null));
+ register(Duration.class, throwException ? new DurationConverter() : new DurationConverter(null));
+ register(MonthDay.class, throwException ? new MonthDayConverter() : new MonthDayConverter(null));
+ register(Period.class, throwException ? new PeriodConverter() : new PeriodConverter(null));
+ register(Year.class, throwException ? new YearConverter() : new YearConverter(null));
+ register(YearMonth.class, throwException ? new YearMonthConverter() : new YearMonthConverter(null));
+ register(ZoneId.class, throwException ? new ZoneIdConverter() : new ZoneIdConverter(null));
+ register(ZoneOffset.class, throwException ? new ZoneOffsetConverter() : new ZoneOffsetConverter(null));
+ // @formatter:on
}
/**
@@ -491,6 +558,7 @@ public class ConvertUtilsBean {
* the default.
*/
private void registerArrays(final boolean throwException, final int defaultArraySize) {
+ // @formatter:off
// Primitives
registerArrayConverter(Boolean.TYPE, new BooleanConverter(), throwException, defaultArraySize);
@@ -516,18 +584,31 @@ public class ConvertUtilsBean {
registerArrayConverter(String.class, new StringConverter(), throwException, defaultArraySize);
// Other
- registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize);
- registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize);
- registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize);
- registerArrayConverter(Path.class, new PathConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize);
- registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize);
- registerArrayConverter(URI.class, new URIConverter(), throwException, defaultArraySize);
- registerArrayConverter(UUID.class, new UUIDConverter(), throwException, defaultArraySize);
-
+ registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize);
+ registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize);
+ registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Path.class, new PathConverter(), throwException, defaultArraySize);
+ registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
+ registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize);
+ registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize);
+ registerArrayConverter(URI.class, new URIConverter(), throwException, defaultArraySize);
+ registerArrayConverter(UUID.class, new UUIDConverter(), throwException, defaultArraySize);
+ registerArrayConverter(LocalDate.class, new LocalDateConverter(), throwException, defaultArraySize);
+ registerArrayConverter(LocalDateTime.class, new LocalDateTimeConverter(), throwException, defaultArraySize);
+ registerArrayConverter(LocalTime.class, new LocalTimeConverter(), throwException, defaultArraySize);
+ registerArrayConverter(OffsetDateTime.class, new OffsetDateTimeConverter(),throwException, defaultArraySize);
+ registerArrayConverter(OffsetTime.class, new OffsetTimeConverter(), throwException, defaultArraySize);
+ registerArrayConverter(ZonedDateTime.class, new ZonedDateTimeConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Duration.class, new DurationConverter(), throwException, defaultArraySize);
+ registerArrayConverter(MonthDay.class, new MonthDayConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Period.class, new PeriodConverter(), throwException, defaultArraySize);
+ registerArrayConverter(Year.class, new YearConverter(), throwException, defaultArraySize);
+ registerArrayConverter(YearMonth.class, new YearMonthConverter(), throwException, defaultArraySize);
+ registerArrayConverter(ZoneId.class, new ZoneIdConverter(), throwException, defaultArraySize);
+ registerArrayConverter(ZoneOffset.class, new ZoneOffsetConverter(), throwException, defaultArraySize);
+ // @formatter:on
}
/**
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java
similarity index 56%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java
index 9713962..a593585 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.Duration;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.Duration</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.Duration
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class DurationConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.Duration</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public DurationConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.Duration</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public DurationConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return Duration.class;
+ }
+
+ /**
+ * <p>Convert a java.time.Duration or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (Duration.class.equals(type)) {
+ return type.cast(Duration.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
index 4386f61..b58c981 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
@@ -26,11 +26,14 @@ import java.time.LocalDate;
* by using a Locale's default format or by specifying a set of format
* patterns (note, there is no default String conversion for Calendar).
* See the {@link DateTimeConverter} documentation for further details.
+ * </p>
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.LocalDate
*/
public final class LocalDateConverter extends DateTimeConverter {
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java
index e151684..3be8a52 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java
@@ -26,11 +26,14 @@ import java.time.LocalDateTime;
* by using a Locale's default format or by specifying a set of format
* patterns (note, there is no default String conversion for Calendar).
* See the {@link DateTimeConverter} documentation for further details.
+ * </p>
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.LocalDateTime
*/
public final class LocalDateTimeConverter extends DateTimeConverter {
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java
similarity index 57%
copy from src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java
index 4386f61..d62333a 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.LocalDate;
+import java.time.LocalTime;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.LocalDate</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.LocalTime</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.LocalTime
*/
-public final class LocalDateConverter extends DateTimeConverter {
+public final class LocalTimeConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.LocalDate</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.LocalTime</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public LocalDateConverter() {
+ public LocalTimeConverter() {
super();
}
/**
- * Construct a <b>java.time.LocalDate</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.LocalTime</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public LocalDateConverter(final Object defaultValue) {
+ public LocalTimeConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class LocalDateConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return LocalDate.class;
+ return LocalTime.class;
+ }
+
+ /**
+ * <p>Convert a java.time.LocalTime or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (LocalTime.class.equals(type)) {
+ return type.cast(LocalTime.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java
similarity index 56%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java
index 9713962..e3258d5 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.MonthDay;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.MonthDay</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.MonthDay
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class MonthDayConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.MonthDay</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public MonthDayConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.MonthDay</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public MonthDayConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return MonthDay.class;
+ }
+
+ /**
+ * <p>Convert a java.time.MonthDay or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (MonthDay.class.equals(type)) {
+ return type.cast(MonthDay.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
index 9713962..deba044 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
@@ -26,11 +26,14 @@ import java.time.OffsetDateTime;
* by using a Locale's default format or by specifying a set of format
* patterns (note, there is no default String conversion for Calendar).
* See the {@link DateTimeConverter} documentation for further details.
+ * </p>
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.OffsetDateTime
*/
public final class OffsetDateTimeConverter extends DateTimeConverter {
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java
similarity index 56%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java
index 9713962..06f3621 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.OffsetTime;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.OffsetTime</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.OffsetTime
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class OffsetTimeConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.OffsetTime</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public OffsetTimeConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.OffsetTime</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public OffsetTimeConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return OffsetTime.class;
+ }
+
+ /**
+ * <p>Convert a java.time.OffsetTime or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (OffsetTime.class.equals(type)) {
+ return type.cast(OffsetTime.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java
similarity index 57%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java
index 9713962..f345500 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.Period;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.Period</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.Period
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class PeriodConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.Period</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public PeriodConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.Period</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public PeriodConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return Period.class;
+ }
+
+ /**
+ * <p>Convert a java.time.Period or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (Period.class.equals(type)) {
+ return type.cast(Period.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java
similarity index 57%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java
index 9713962..6055265 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.Year;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.Year</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.Year
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class YearConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.Year</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public YearConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.Year</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public YearConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return Year.class;
+ }
+
+ /**
+ * <p>Convert a java.time.Year or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (Year.class.equals(type)) {
+ return type.cast(Year.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java
similarity index 57%
copy from src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java
index 4386f61..c89a53a 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.LocalDate;
+import java.time.YearMonth;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.LocalDate</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.YearMonth</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.YearMonth
*/
-public final class LocalDateConverter extends DateTimeConverter {
+public final class YearMonthConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.LocalDate</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.YearMonth</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public LocalDateConverter() {
+ public YearMonthConverter() {
super();
}
/**
- * Construct a <b>java.time.LocalDate</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.YearMonth</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public LocalDateConverter(final Object defaultValue) {
+ public YearMonthConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class LocalDateConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return LocalDate.class;
+ return YearMonth.class;
+ }
+
+ /**
+ * <p>Convert a java.time.YearMonth or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (YearMonth.class.equals(type)) {
+ return type.cast(YearMonth.parse((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java
similarity index 57%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java
index 9713962..90f3e8e 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.ZoneId;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.ZoneId</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.ZoneId
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class ZoneIdConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.ZoneId</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public ZoneIdConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.ZoneId</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public ZoneIdConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return ZoneId.class;
+ }
+
+ /**
+ * <p>Convert a java.time.ZoneId or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (ZoneId.class.equals(type)) {
+ return type.cast(ZoneId.of((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java
similarity index 56%
copy from src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
copy to src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java
index 9713962..eeaccc5 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java
@@ -16,41 +16,38 @@
*/
package org.apache.commons.beanutils2.converters;
-import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from <b>java.time.OffsetDateTime</b> objects.
- * <p>
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>java.time.ZoneOffset</b> objects.
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.ZoneOffset
*/
-public final class OffsetDateTimeConverter extends DateTimeConverter {
+public final class ZoneOffsetConverter extends AbstractConverter {
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that throws
+ * Construct a <b>java.time.ZoneOffset</b> <i>Converter</i> that throws
* a <code>ConversionException</code> if an error occurs.
*/
- public OffsetDateTimeConverter() {
+ public ZoneOffsetConverter() {
super();
}
/**
- * Construct a <b>java.time.OffsetDateTime</b> <i>Converter</i> that returns
+ * Construct a <b>java.time.ZoneOffset</b> <i>Converter</i> that returns
* a default value if an error occurs.
*
* @param defaultValue The default value to be returned
* if the value to be converted is missing or an error
* occurs converting the value.
*/
- public OffsetDateTimeConverter(final Object defaultValue) {
+ public ZoneOffsetConverter(final Object defaultValue) {
super(defaultValue);
}
@@ -58,10 +55,30 @@ public final class OffsetDateTimeConverter extends DateTimeConverter {
* Return the default type this <code>Converter</code> handles.
*
* @return The default type this <code>Converter</code> handles.
+ * @since 2.0
*/
@Override
protected Class<?> getDefaultType() {
- return OffsetDateTime.class;
+ return ZoneOffset.class;
+ }
+
+ /**
+ * <p>Convert a java.time.ZoneOffset or object into a String.</p>
+ *
+ * @param <T> Target type of the conversion.
+ * @param type Data type to which this value should be converted.
+ * @param value The input value to be converted.
+ * @return The converted value.
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 2.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+ if (ZoneOffset.class.equals(type)) {
+ return type.cast(ZoneOffset.of((String.valueOf(value))));
+ }
+
+ throw conversionException(type, value);
}
}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java
index c43c56d..d95e545 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java
@@ -26,11 +26,14 @@ import java.time.ZonedDateTime;
* by using a Locale's default format or by specifying a set of format
* patterns (note, there is no default String conversion for Calendar).
* See the {@link DateTimeConverter} documentation for further details.
+ * </p>
* <p>
* Can be configured to either return a <i>default value</i> or throw a
* <code>ConversionException</code> if a conversion error occurs.
+ * </p>
*
* @since 2.0
+ * @see java.time.ZonedDateTime
*/
public final class ZonedDateTimeConverter extends DateTimeConverter {
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/DurationConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/DurationConverterTestCase.java
new file mode 100644
index 0000000..a32fda8
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/DurationConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.Duration;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the DurationConverter class.
+ *
+ */
+public class DurationConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(DurationConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public DurationConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return Duration.class;
+ }
+
+ protected Converter makeConverter() {
+ return new DurationConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "PT20.345S",
+ "PT15M",
+ "PT51H4M"
+ };
+
+ final Duration[] expected = {
+ Duration.parse("PT20.345S"),
+ Duration.parse("PT15M"),
+ Duration.parse("P2DT3H4M")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(Duration.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/LocalTimeConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/LocalTimeConverterTestCase.java
new file mode 100644
index 0000000..7130765
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/LocalTimeConverterTestCase.java
@@ -0,0 +1,116 @@
+/*
+ * 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.converters;
+
+
+import java.time.LocalTime;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the LocalTimeConverter class.
+ *
+ */
+public class LocalTimeConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(LocalTimeConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public LocalTimeConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return LocalTime.class;
+ }
+
+ protected Converter makeConverter() {
+ return new LocalTimeConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "10:15",
+ "08:45:30"
+ };
+
+ final LocalTime[] expected = {
+ LocalTime.parse("10:15"),
+ LocalTime.parse("08:45:30")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(LocalTime.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/MonthDayConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/MonthDayConverterTestCase.java
new file mode 100644
index 0000000..5d5ef64
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/MonthDayConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.MonthDay;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the MonthDayConverter class.
+ *
+ */
+public class MonthDayConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(MonthDayConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public MonthDayConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return MonthDay.class;
+ }
+
+ protected Converter makeConverter() {
+ return new MonthDayConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "--12-03",
+ "--05-30",
+ "--01-01"
+ };
+
+ final MonthDay[] expected = {
+ MonthDay.parse("--12-03"),
+ MonthDay.parse("--05-30"),
+ MonthDay.parse("--01-01")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(MonthDay.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/OffsetTimeConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/OffsetTimeConverterTestCase.java
new file mode 100644
index 0000000..1f7eb8f
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/OffsetTimeConverterTestCase.java
@@ -0,0 +1,116 @@
+/*
+ * 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.converters;
+
+
+import java.time.OffsetTime;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the OffsetTimeConverter class.
+ *
+ */
+public class OffsetTimeConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(OffsetTimeConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public OffsetTimeConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return OffsetTime.class;
+ }
+
+ protected Converter makeConverter() {
+ return new OffsetTimeConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "10:15+01:00",
+ "08:45:30+14:00"
+ };
+
+ final OffsetTime[] expected = {
+ OffsetTime.parse("10:15+01:00"),
+ OffsetTime.parse("08:45:30+14:00")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(OffsetTime.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/PeriodConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/PeriodConverterTestCase.java
new file mode 100644
index 0000000..c6e06fa
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/PeriodConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.Period;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the PeriodConverter class.
+ *
+ */
+public class PeriodConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(PeriodConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public PeriodConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return Period.class;
+ }
+
+ protected Converter makeConverter() {
+ return new PeriodConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "P2Y",
+ "P5D",
+ "P1Y2M3D"
+ };
+
+ final Period[] expected = {
+ Period.parse("P2Y"),
+ Period.parse("P5D"),
+ Period.parse("P1Y2M3D")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(Period.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/YearConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/YearConverterTestCase.java
new file mode 100644
index 0000000..2930c3b
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/YearConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.Year;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the YearConverter class.
+ *
+ */
+public class YearConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(YearConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public YearConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return Year.class;
+ }
+
+ protected Converter makeConverter() {
+ return new YearConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "2019",
+ "1974",
+ "2112"
+ };
+
+ final Year[] expected = {
+ Year.parse("2019"),
+ Year.parse("1974"),
+ Year.parse("2112")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(Year.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/YearMonthConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/YearMonthConverterTestCase.java
new file mode 100644
index 0000000..ba6833e
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/YearMonthConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.YearMonth;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the YearMonthConverter class.
+ *
+ */
+public class YearMonthConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(YearMonthConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public YearMonthConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return YearMonth.class;
+ }
+
+ protected Converter makeConverter() {
+ return new YearMonthConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "2007-12",
+ "1974-05",
+ "2112-01"
+ };
+
+ final YearMonth[] expected = {
+ YearMonth.parse("2007-12"),
+ YearMonth.parse("1974-05"),
+ YearMonth.parse("2112-01")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(YearMonth.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/ZoneIdConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/ZoneIdConverterTestCase.java
new file mode 100644
index 0000000..4021866
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/ZoneIdConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.ZoneId;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the ZoneIdConverter class.
+ *
+ */
+public class ZoneIdConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(ZoneIdConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public ZoneIdConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return ZoneId.class;
+ }
+
+ protected Converter makeConverter() {
+ return new ZoneIdConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "America/New_York",
+ "-05:00",
+ "Australia/Sydney"
+ };
+
+ final ZoneId[] expected = {
+ ZoneId.of("America/New_York"),
+ ZoneId.of("-05:00"),
+ ZoneId.of("Australia/Sydney")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(ZoneId.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverterTestCase.java
new file mode 100644
index 0000000..9b68285
--- /dev/null
+++ b/src/test/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverterTestCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.converters;
+
+
+import java.time.ZoneOffset;
+
+import org.apache.commons.beanutils2.ConversionException;
+import org.apache.commons.beanutils2.Converter;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Test Case for the ZoneOffsetConverter class.
+ *
+ */
+public class ZoneOffsetConverterTestCase extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(ZoneOffsetConverterTestCase.class);
+ }
+
+ // ------------------------------------------------------------------------
+
+ private Converter converter = null;
+
+ // ------------------------------------------------------------------------
+
+ public ZoneOffsetConverterTestCase(final String name) {
+ super(name);
+ }
+
+ protected Class<?> getExpectedType() {
+ return ZoneOffset.class;
+ }
+
+ protected Converter makeConverter() {
+ return new ZoneOffsetConverter();
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void setUp() throws Exception {
+ converter = makeConverter();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ converter = null;
+ }
+
+ // ------------------------------------------------------------------------
+
+ public void testSimpleConversion() throws Exception {
+ final String[] message= {
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ "from String",
+ };
+
+ final Object[] input = {
+ "-12:00",
+ "+14:00",
+ "+02:00"
+ };
+
+ final ZoneOffset[] expected = {
+ ZoneOffset.of("-12:00"),
+ ZoneOffset.of("+14:00"),
+ ZoneOffset.of("+02:00")
+ };
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(message[i] + " to URI",expected[i],converter.convert(ZoneOffset.class,input[i]));
+ assertEquals(message[i] + " to null type",expected[i],converter.convert(null,input[i]));
+ }
+
+ for(int i=0;i<expected.length;i++) {
+ assertEquals(input[i] + " to String", input[i], converter.convert(String.class, expected[i]));
+ }
+ }
+
+ /**
+ * Tests a conversion to an unsupported type.
+ */
+ public void testUnsupportedType() {
+ try {
+ converter.convert(Integer.class, "http://www.apache.org");
+ fail("Unsupported type could be converted!");
+ } catch (final ConversionException cex) {
+ // expected result
+ }
+ }
+}
+