public final class PropertyConverter extends Object
Modifier and Type | Method and Description |
---|---|
static Object |
to(Class<?> cls,
Object value,
DefaultConversionHandler convHandler)
Performs a data type conversion from the specified value object to the given target data class.
|
static BigDecimal |
toBigDecimal(Object value)
Convert the specified object into a BigDecimal.
|
static BigInteger |
toBigInteger(Object value)
Convert the specified object into a BigInteger.
|
static Boolean |
toBoolean(Object value)
Convert the specified object into a Boolean.
|
static Byte |
toByte(Object value)
Convert the specified object into a Byte.
|
static Calendar |
toCalendar(Object value,
String format)
Convert the specified object into a Calendar.
|
static Character |
toCharacter(Object value)
Converts the specified value object to a
Character . |
static Color |
toColor(Object value)
Convert the specified object into a Color.
|
static Date |
toDate(Object value,
String format)
Convert the specified object into a Date.
|
static Double |
toDouble(Object value)
Convert the specified object into a Double.
|
static Duration |
toDuration(Object value)
Convert the specified object into a Duration.
|
static File |
toFile(Object value)
Convert the specified object into a File.
|
static Float |
toFloat(Object value)
Convert the specified object into a Float.
|
static Integer |
toInteger(Object value)
Convert the specified object into an Integer.
|
static Locale |
toLocale(Object value)
Convert the specified object into a Locale.
|
static Long |
toLong(Object value)
Convert the specified object into a Long.
|
static Path |
toPath(Object value)
Convert the specified object into a Path.
|
static Pattern |
toPattern(Object value)
Convert the specified object into a Pattern.
|
static Short |
toShort(Object value)
Convert the specified object into a Short.
|
static URI |
toURI(Object value)
Convert the specified object into an URI.
|
static URL |
toURL(Object value)
Convert the specified object into an URL.
|
public static Object to(Class<?> cls, Object value, DefaultConversionHandler convHandler) throws ConversionException
DefaultConversionHandler
object. If the class is a primitive type (Integer.TYPE, Boolean.TYPE, etc), the value returned will use the wrapper
type (Integer.class, Boolean.class, etc).cls
- the target class of the converted valuevalue
- the value to convertconvHandler
- the conversion handler objectConversionException
- if the value is not compatible with the requested typepublic static Boolean toBoolean(Object value) throws ConversionException
org.apache.commons.lang.BooleanUtils
class from
the Commons Lang project is used to perform this conversion. This
class accepts some more tokens for the boolean value of true, e.g. yes
and on
. Please refer to
the documentation of this class for more details.value
- the value to convertConversionException
- thrown if the value cannot be converted to a booleanpublic static Character toCharacter(Object value) throws ConversionException
Character
. This method converts the passed in object to a string. If
the string has exactly one character, this character is returned as result. Otherwise, conversion fails.value
- the value to be convertedCharacter
objectConversionException
- if the conversion is not possiblepublic static Byte toByte(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a bytepublic static Short toShort(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a shortpublic static Integer toInteger(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to an integerpublic static Long toLong(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Longpublic static Float toFloat(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Floatpublic static Double toDouble(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Doublepublic static Duration toDuration(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Durationpublic static BigInteger toBigInteger(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a BigIntegerpublic static BigDecimal toBigDecimal(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a BigDecimalpublic static File toFile(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Filepublic static Path toPath(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Pathpublic static URI toURI(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to an URIpublic static URL toURL(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to an URLpublic static Pattern toPattern(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Patternpublic static Locale toLocale(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Localepublic static Color toColor(Object value) throws ConversionException
value
- the value to convertConversionException
- thrown if the value cannot be converted to a Colorpublic static Date toDate(Object value, String format) throws ConversionException
value
- the value to convertformat
- the DateFormat pattern to parse String valuesConversionException
- thrown if the value cannot be converted to a Calendarpublic static Calendar toCalendar(Object value, String format) throws ConversionException
value
- the value to convertformat
- the DateFormat pattern to parse String valuesConversionException
- thrown if the value cannot be converted to a CalendarCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.