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
Converters, and re-establish the
standard Converters. |
static void |
deregister(Class<?> clazz)
Remove any registered
Converter for the specified destination
Class. |
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. |
public 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 Converters, 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–2019 The Apache Software Foundation. All rights reserved.