public class ConvertUtils extends 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.
ConvertUtilsBean
Constructor and Description |
---|
ConvertUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
convert(Object value)
Convert the specified value into a String.
|
static Object |
convert(Object value,
Class<?> targetType)
Convert the value to an object of the specified class (if
possible).
|
static Object |
convert(String[] values,
Class<?> clazz)
Convert an array of specified values to an array of objects of the
specified class (if possible).
|
static Object |
convert(String value,
Class<?> clazz)
Convert the specified value to an object of the specified class (if
possible).
|
static void |
deregister()
Remove all registered
Converter s, and re-establish the
standard Converters. |
static void |
deregister(Class<?> clazz)
Remove any registered
Converter for the specified destination
Class . |
static boolean |
getDefaultBoolean()
Deprecated.
Register replacement converters for Boolean.TYPE and
Boolean.class instead
|
static byte |
getDefaultByte()
Deprecated.
Register replacement converters for Byte.TYPE and
Byte.class instead
|
static char |
getDefaultCharacter()
Deprecated.
Register replacement converters for Character.TYPE and
Character.class instead
|
static double |
getDefaultDouble()
Deprecated.
Register replacement converters for Double.TYPE and
Double.class instead
|
static float |
getDefaultFloat()
Deprecated.
Register replacement converters for Float.TYPE and
Float.class instead
|
static int |
getDefaultInteger()
Deprecated.
Register replacement converters for Integer.TYPE and
Integer.class instead
|
static long |
getDefaultLong()
Deprecated.
Register replacement converters for Long.TYPE and
Long.class instead
|
static short |
getDefaultShort()
Deprecated.
Register replacement converters for Short.TYPE and
Short.class instead
|
static Converter |
lookup(Class<?> clazz)
Look up and return any registered
Converter for the specified
destination class; if there is no registered Converter, return
null . |
static Converter |
lookup(Class<?> sourceType,
Class<?> targetType)
Look up and return any registered
Converter for the specified
source and destination class; if there is no registered Converter,
return null . |
static <T> Class<T> |
primitiveToWrapper(Class<T> type)
Change primitive Class types to the associated wrapper class.
|
static void |
register(Converter converter,
Class<?> clazz)
Register a custom
Converter for the specified destination
Class , replacing any previously registered Converter. |
static void |
setDefaultBoolean(boolean newDefaultBoolean)
Deprecated.
Register replacement converters for Boolean.TYPE and
Boolean.class instead
|
static void |
setDefaultByte(byte newDefaultByte)
Deprecated.
Register replacement converters for Byte.TYPE and
Byte.class instead
|
static void |
setDefaultCharacter(char newDefaultCharacter)
Deprecated.
Register replacement converters for Character.TYPE and
Character.class instead
|
static void |
setDefaultDouble(double newDefaultDouble)
Deprecated.
Register replacement converters for Double.TYPE and
Double.class instead
|
static void |
setDefaultFloat(float newDefaultFloat)
Deprecated.
Register replacement converters for Float.TYPE and
Float.class instead
|
static void |
setDefaultInteger(int newDefaultInteger)
Deprecated.
Register replacement converters for Integer.TYPE and
Integer.class instead
|
static void |
setDefaultLong(long newDefaultLong)
Deprecated.
Register replacement converters for Long.TYPE and
Long.class instead
|
static void |
setDefaultShort(short newDefaultShort)
Deprecated.
Register replacement converters for Short.TYPE and
Short.class instead
|
@Deprecated public static boolean getDefaultBoolean()
@Deprecated public static void setDefaultBoolean(boolean newDefaultBoolean)
newDefaultBoolean
- The default Boolean value@Deprecated public static byte getDefaultByte()
@Deprecated public static void setDefaultByte(byte newDefaultByte)
newDefaultByte
- The default Byte value@Deprecated public static char getDefaultCharacter()
@Deprecated public static void setDefaultCharacter(char newDefaultCharacter)
newDefaultCharacter
- The default Character value@Deprecated public static double getDefaultDouble()
@Deprecated public static void setDefaultDouble(double newDefaultDouble)
newDefaultDouble
- The default Double value@Deprecated public static float getDefaultFloat()
@Deprecated public static void setDefaultFloat(float newDefaultFloat)
newDefaultFloat
- The default Float value@Deprecated public static int getDefaultInteger()
@Deprecated public static void setDefaultInteger(int newDefaultInteger)
newDefaultInteger
- The default Integer value@Deprecated public static long getDefaultLong()
@Deprecated public static void setDefaultLong(long newDefaultLong)
newDefaultLong
- The default Long value@Deprecated public static short getDefaultShort()
@Deprecated public static void setDefaultShort(short newDefaultShort)
newDefaultShort
- The default Short valuepublic static String convert(Object value)
Convert the specified value into a String.
For more details see ConvertUtilsBean
.
value
- Value to be converted (may be null)ConvertUtilsBean.convert(Object)
public static Object convert(String value, 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
.
value
- Value to be converted (may be null)clazz
- Java class to be converted to (must not be null)ConvertUtilsBean.convert(String, Class)
public static Object convert(String[] values, Class<?> clazz)
Convert an array of specified values to an array of objects of the specified class (if possible).
For more details see ConvertUtilsBean
.
values
- Array of values to be convertedclazz
- Java array or element class to be converted to (must not be null)ConvertUtilsBean.convert(String[], Class)
public static Object convert(Object value, Class<?> targetType)
Convert the value to an object of the specified class (if possible).
value
- Value to be converted (may be null)targetType
- Class of the value to be converted to (must not be null)ConversionException
- if thrown by an underlying Converterpublic static void deregister()
Remove all registered Converter
s, and re-establish the
standard Converters.
For more details see ConvertUtilsBean
.
ConvertUtilsBean.deregister()
public static void deregister(Class<?> clazz)
Remove any registered Converter
for the specified destination
Class
.
For more details see ConvertUtilsBean
.
clazz
- Class for which to remove a registered ConverterConvertUtilsBean.deregister(Class)
public static Converter lookup(Class<?> clazz)
Look up and return any registered Converter
for the specified
destination class; if there is no registered Converter, return
null
.
For more details see ConvertUtilsBean
.
clazz
- Class for which to return a registered ConverterConverter
or null
if not foundConvertUtilsBean.lookup(Class)
public static Converter lookup(Class<?> sourceType, Class<?> targetType)
Converter
for the specified
source and destination class; if there is no registered Converter,
return null
.sourceType
- Class of the value being convertedtargetType
- Class of the value to be converted toConverter
or null
if not foundpublic static void register(Converter converter, Class<?> clazz)
Register a custom Converter
for the specified destination
Class
, replacing any previously registered Converter.
For more details see ConvertUtilsBean
.
converter
- Converter to be registeredclazz
- Destination class for conversions performed by this
ConverterConvertUtilsBean.register(Converter, Class)
public static <T> Class<T> primitiveToWrapper(Class<T> type)
T
- The type to be checked.type
- The class type to check.Copyright © 2000–2014 The Apache Software Foundation. All rights reserved.