public class ConverterUtils 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 ConverterBean which provides the
implementations for these methods.
ConverterBean| 构造器和说明 |
|---|
ConverterUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Object |
convert(Class<?> targetType,
Object value)
Convert the value to an object of the specified class (if
possible).
|
static String |
convert(Object value)
Convert the specified value into a String.
|
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 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 ConverterBean.
value - Value to be converted (may be null)ConverterBean.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 ConverterBean.
value - Value to be converted (may be null)clazz - Java class to be converted toConverterBean.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 ConverterBean.
values - Array of values to be convertedclazz - Java array or element class to be converted toConverterBean.convert(String[], Class)public static Object convert(Class<?> targetType, Object value)
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 toConversionException - if thrown by an underlying Converterpublic static void deregister()
Remove all registered Converters, and re-establish the
standard Converters.
For more details see ConverterBean.
public static void deregister(Class clazz)
Remove any registered Converter for the specified destination
Class.
For more details see ConverterBean.
clazz - Class for which to remove a registered ConverterConverterBean.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 ConverterBean.
clazz - Class for which to return a registered ConverterConverter or null if not foundConverterBean.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 ConverterBean.
converter - Converter to be registeredclazz - Destination class for conversions performed by this ConverterConverterBean.register(Converter, Class)Copyright © 2021–2022. All rights reserved.