Class ConvertUtils
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:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Converts the specified value into a String.static Object
Converts the value to an object of the specified class (if possible).static Object
Convert an array of specified values to an array of objects of the specified class (if possible).static Object
Converts the specified value to an object of the specified class (if possible).static void
Remove all registeredConverter
s, and re-establish the standard Converters.static void
deregister
(Class<?> clazz) Remove any registeredConverter
for the specified destinationClass
.static <T> Converter<T>
Look up and return any registeredConverter
for the specified source and destination class; if there is no registered Converter, returnnull
.static <T> Converter<T>
Look up and return any registeredConverter
for the specified destination class; if there is no registered Converter, returnnull
.static <T> Class<T>
primitiveToWrapper
(Class<T> type) Change primitive Class types to the associated wrapper class.static <T> void
Register a customConverter
for the specified destinationClass
, replacing any previously registered Converter.
-
Constructor Details
-
ConvertUtils
public ConvertUtils()
-
-
Method Details
-
convert
Converts 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:
-
convert
Converts 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
Converts 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:
-
convert
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:
-
deregister
Remove all registered
Converter
s, and re-establish the standard Converters.For more details see
ConvertUtilsBean
.- See Also:
-
deregister
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:
-
lookup
Look up and return any registeredConverter
for the specified source and destination class; if there is no registered Converter, returnnull
.- Type Parameters:
T
- The converter type.- Parameters:
sourceType
- Class of the value being convertedtargetType
- Class of the value to be converted to- Returns:
- The registered
Converter
ornull
if not found
-
lookup
Look up and return any registered
Converter
for the specified destination class; if there is no registered Converter, returnnull
.For more details see
ConvertUtilsBean
.- Type Parameters:
T
- The converter type.- Parameters:
clazz
- Class for which to return a registered Converter- Returns:
- The registered
Converter
ornull
if not found - See Also:
-
primitiveToWrapper
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
Register a custom
Converter
for the specified destinationClass
, replacing any previously registered Converter.For more details see
ConvertUtilsBean
.- Type Parameters:
T
- The converter type.- Parameters:
converter
- Converter to be registeredclazz
- Destination class for conversions performed by this Converter- See Also:
-