public class ConvertUtils extends Object
Modifier | Constructor and Description |
---|---|
protected |
ConvertUtils() |
Modifier and Type | Method and Description |
---|---|
<T> T |
cast(Class<T> clazz,
Object value)
Casts an Object into the expected type.
|
Object |
convert(Class<?> clazz,
Object value)
Converts an Object into the expected type, handling Arrays and Collections.
|
void |
deregister(Class<?> type)
Removes registered converter for this class.
|
static ConvertUtils |
getDefaultInstance() |
static boolean |
isConvertible(Class<?> sourceType,
Class<?> targetType)
Tells if source can be cast to target
|
static boolean |
isHandled(Class<?> type)
Tells if this type is handled by a dedicated converter.
|
IConverter |
lookup(Class<?> clazz)
Searches for a Converter able to handle this class or interface.
|
IConverter |
lookup(Class<?> sourceType,
Class<?> targetType)
Searches for a Converter able to handle conversions from sourceType to targetType.
|
void |
registerConverter(IConverter converter)
Convenience method to not override converter types.
|
void |
registerConverter(IConverter converter,
Class<?>... forTypes)
Registers a new Converter instance.
|
void |
registerDefaultConverters()
Reloads registration of defaults converters.
|
String |
toString(Object value)
Safe shortcut to for the
cast(Class, Object) with String as a target class,
handling Exceptions by returning the native Object.toString() result. |
public static ConvertUtils getDefaultInstance()
public void registerDefaultConverters()
public void deregister(Class<?> type)
public void registerConverter(IConverter converter)
public void registerConverter(IConverter converter, Class<?>... forTypes)
converter
- Converter to registerforTypes
- If not null, ignores Converter types and uses these.public IConverter lookup(Class<?> clazz)
public IConverter lookup(Class<?> sourceType, Class<?> targetType)
public <T> T cast(Class<T> clazz, Object value) throws UtilsException
clazz
- The target classvalue
- The value to castUtilsException
- If cast is impossibleIConverter.convertToType(Class, Object)
public Object convert(Class<?> clazz, Object value) throws UtilsException
clazz
- The target classvalue
- The value to convertUtilsException
- If conversion is impossibleIConverter.typeConversion(Class, Object)
public String toString(Object value)
cast(Class, Object)
with String
as a target class,
handling Exceptions by returning the native Object.toString()
result.public static boolean isConvertible(Class<?> sourceType, Class<?> targetType)
public static boolean isHandled(Class<?> type)