Class ConvertUtils
- java.lang.Object
-
- org.apache.commons.beanutils.ConvertUtils
-
public class ConvertUtils extends java.lang.Object
Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class.
For more details, see
ConvertUtilsBean
which provides the implementations for these methods.- See Also:
ConvertUtilsBean
-
-
Constructor Summary
Constructors Constructor Description ConvertUtils()
Deprecated.Will be private in 2.0.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
convert(java.lang.Object value)
Convert the specified value into a String.static java.lang.Object
convert(java.lang.Object value, java.lang.Class<?> targetType)
Convert the value to an object of the specified class (if possible).static java.lang.Object
convert(java.lang.String[] values, java.lang.Class<?> clazz)
Convert an array of specified values to an array of objects of the specified class (if possible).static java.lang.Object
convert(java.lang.String value, java.lang.Class<?> clazz)
Convert the specified value to an object of the specified class (if possible).static void
deregister()
Remove all registeredConverter
s, and re-establish the standard Converters.static void
deregister(java.lang.Class<?> clazz)
Remove any registeredConverter
for the specified destinationClass
.static boolean
getDefaultBoolean()
Deprecated.Register replacement converters for Boolean.TYPE and Boolean.class insteadstatic byte
getDefaultByte()
Deprecated.Register replacement converters for Byte.TYPE and Byte.class insteadstatic char
getDefaultCharacter()
Deprecated.Register replacement converters for Character.TYPE and Character.class insteadstatic double
getDefaultDouble()
Deprecated.Register replacement converters for Double.TYPE and Double.class insteadstatic float
getDefaultFloat()
Deprecated.Register replacement converters for Float.TYPE and Float.class insteadstatic int
getDefaultInteger()
Deprecated.Register replacement converters for Integer.TYPE and Integer.class insteadstatic long
getDefaultLong()
Deprecated.Register replacement converters for Long.TYPE and Long.class insteadstatic short
getDefaultShort()
Deprecated.Register replacement converters for Short.TYPE and Short.class insteadstatic Converter
lookup(java.lang.Class<?> clazz)
Look up and return any registeredConverter
for the specified destination class; if there is no registered Converter, returnnull
.static Converter
lookup(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
Look up and return any registeredConverter
for the specified source and destination class; if there is no registered Converter, returnnull
.static <T> java.lang.Class<T>
primitiveToWrapper(java.lang.Class<T> type)
Change primitive Class types to the associated wrapper class.static void
register(Converter converter, java.lang.Class<?> clazz)
Register a customConverter
for the specified destinationClass
, replacing any previously registered Converter.static void
setDefaultBoolean(boolean newDefaultBoolean)
Deprecated.Register replacement converters for Boolean.TYPE and Boolean.class insteadstatic void
setDefaultByte(byte newDefaultByte)
Deprecated.Register replacement converters for Byte.TYPE and Byte.class insteadstatic void
setDefaultCharacter(char newDefaultCharacter)
Deprecated.Register replacement converters for Character.TYPE and Character.class insteadstatic void
setDefaultDouble(double newDefaultDouble)
Deprecated.Register replacement converters for Double.TYPE and Double.class insteadstatic void
setDefaultFloat(float newDefaultFloat)
Deprecated.Register replacement converters for Float.TYPE and Float.class insteadstatic void
setDefaultInteger(int newDefaultInteger)
Deprecated.Register replacement converters for Integer.TYPE and Integer.class insteadstatic void
setDefaultLong(long newDefaultLong)
Deprecated.Register replacement converters for Long.TYPE and Long.class insteadstatic void
setDefaultShort(short newDefaultShort)
Deprecated.Register replacement converters for Short.TYPE and Short.class instead
-
-
-
Method Detail
-
convert
public static java.lang.String convert(java.lang.Object value)
Convert the specified value into a String.
For more details see
ConvertUtilsBean
.- Parameters:
value
- Value to be converted (may be null)- Returns:
- The converted String value or null if value is null
- See Also:
ConvertUtilsBean.convert(Object)
-
convert
public static java.lang.Object convert(java.lang.Object value, java.lang.Class<?> targetType)
Convert the value to an object of the specified class (if possible).
- Parameters:
value
- Value to be converted (may be null)targetType
- Class of the value to be converted to (must not be null)- Returns:
- The converted value
- Throws:
ConversionException
- if thrown by an underlying Converter
-
convert
public static java.lang.Object convert(java.lang.String value, java.lang.Class<?> clazz)
Convert the specified value to an object of the specified class (if possible). Otherwise, return a String representation of the value.
For more details see
ConvertUtilsBean
.- Parameters:
value
- Value to be converted (may be null)clazz
- Java class to be converted to (must not be null)- Returns:
- The converted value
- See Also:
ConvertUtilsBean.convert(String, Class)
-
convert
public static java.lang.Object convert(java.lang.String[] values, java.lang.Class<?> clazz)
Convert an array of specified values to an array of objects of the specified class (if possible).
For more details see
ConvertUtilsBean
.- Parameters:
values
- Array of values to be convertedclazz
- Java array or element class to be converted to (must not be null)- Returns:
- The converted value
- See Also:
ConvertUtilsBean.convert(String[], Class)
-
deregister
public static void deregister()
Remove all registered
Converter
s, and re-establish the standard Converters.For more details see
ConvertUtilsBean
.- See Also:
ConvertUtilsBean.deregister()
-
deregister
public static void deregister(java.lang.Class<?> clazz)
Remove any registered
Converter
for the specified destinationClass
.For more details see
ConvertUtilsBean
.- Parameters:
clazz
- Class for which to remove a registered Converter- See Also:
ConvertUtilsBean.deregister(Class)
-
getDefaultBoolean
@Deprecated public static boolean getDefaultBoolean()
Deprecated.Register replacement converters for Boolean.TYPE and Boolean.class insteadGets the default value for Boolean conversions.- Returns:
- The default Boolean value
-
getDefaultByte
@Deprecated public static byte getDefaultByte()
Deprecated.Register replacement converters for Byte.TYPE and Byte.class insteadGets the default value for Byte conversions.- Returns:
- The default Byte value
-
getDefaultCharacter
@Deprecated public static char getDefaultCharacter()
Deprecated.Register replacement converters for Character.TYPE and Character.class insteadGets the default value for Character conversions.- Returns:
- The default Character value
-
getDefaultDouble
@Deprecated public static double getDefaultDouble()
Deprecated.Register replacement converters for Double.TYPE and Double.class insteadGets the default value for Double conversions.- Returns:
- The default Double value
-
getDefaultFloat
@Deprecated public static float getDefaultFloat()
Deprecated.Register replacement converters for Float.TYPE and Float.class insteadGet the default value for Float conversions.- Returns:
- The default Float value
-
getDefaultInteger
@Deprecated public static int getDefaultInteger()
Deprecated.Register replacement converters for Integer.TYPE and Integer.class insteadGets the default value for Integer conversions.- Returns:
- The default Integer value
-
getDefaultLong
@Deprecated public static long getDefaultLong()
Deprecated.Register replacement converters for Long.TYPE and Long.class insteadGets the default value for Long conversions.- Returns:
- The default Long value
-
getDefaultShort
@Deprecated public static short getDefaultShort()
Deprecated.Register replacement converters for Short.TYPE and Short.class insteadGets the default value for Short conversions.- Returns:
- The default Short value
-
lookup
public static Converter lookup(java.lang.Class<?> clazz)
Look up and return any registered
Converter
for the specified destination class; if there is no registered Converter, returnnull
.For more details see
ConvertUtilsBean
.- Parameters:
clazz
- Class for which to return a registered Converter- Returns:
- The registered
Converter
ornull
if not found - See Also:
ConvertUtilsBean.lookup(Class)
-
lookup
public static Converter lookup(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
Look up and return any registeredConverter
for the specified source and destination class; if there is no registered Converter, returnnull
.- Parameters:
sourceType
- Class of the value being convertedtargetType
- Class of the value to be converted to- Returns:
- The registered
Converter
ornull
if not found
-
primitiveToWrapper
public static <T> java.lang.Class<T> primitiveToWrapper(java.lang.Class<T> type)
Change primitive Class types to the associated wrapper class. This is useful for concrete converter implementations which typically treat primitive types like their corresponding wrapper types.- Type Parameters:
T
- The type to be checked.- Parameters:
type
- The class type to check.- Returns:
- The converted type.
- Since:
- 1.9
-
register
public static void register(Converter converter, java.lang.Class<?> clazz)
Register a custom
Converter
for the specified destinationClass
, replacing any previously registered Converter.For more details see
ConvertUtilsBean
.- Parameters:
converter
- Converter to be registeredclazz
- Destination class for conversions performed by this Converter- See Also:
ConvertUtilsBean.register(Converter, Class)
-
setDefaultBoolean
@Deprecated public static void setDefaultBoolean(boolean newDefaultBoolean)
Deprecated.Register replacement converters for Boolean.TYPE and Boolean.class insteadSets the default value for Boolean conversions.- Parameters:
newDefaultBoolean
- The default Boolean value
-
setDefaultByte
@Deprecated public static void setDefaultByte(byte newDefaultByte)
Deprecated.Register replacement converters for Byte.TYPE and Byte.class insteadSets the default value for Byte conversions.- Parameters:
newDefaultByte
- The default Byte value
-
setDefaultCharacter
@Deprecated public static void setDefaultCharacter(char newDefaultCharacter)
Deprecated.Register replacement converters for Character.TYPE and Character.class insteadSets the default value for Character conversions.- Parameters:
newDefaultCharacter
- The default Character value
-
setDefaultDouble
@Deprecated public static void setDefaultDouble(double newDefaultDouble)
Deprecated.Register replacement converters for Double.TYPE and Double.class insteadSets the default value for Double conversions.- Parameters:
newDefaultDouble
- The default Double value
-
setDefaultFloat
@Deprecated public static void setDefaultFloat(float newDefaultFloat)
Deprecated.Register replacement converters for Float.TYPE and Float.class insteadSets the default value for Float conversions.- Parameters:
newDefaultFloat
- The default Float value
-
setDefaultInteger
@Deprecated public static void setDefaultInteger(int newDefaultInteger)
Deprecated.Register replacement converters for Integer.TYPE and Integer.class insteadSets the default value for Integer conversions.- Parameters:
newDefaultInteger
- The default Integer value
-
setDefaultLong
@Deprecated public static void setDefaultLong(long newDefaultLong)
Deprecated.Register replacement converters for Long.TYPE and Long.class insteadSets the default value for Long conversions.- Parameters:
newDefaultLong
- The default Long value
-
setDefaultShort
@Deprecated public static void setDefaultShort(short newDefaultShort)
Deprecated.Register replacement converters for Short.TYPE and Short.class insteadSets the default value for Short conversions.- Parameters:
newDefaultShort
- The default Short value
-
-