public class ConverterUtil extends Object
ConvertUtils
or trying to get it from this package.| Modifier and Type | Field and Description |
|---|---|
protected static String |
CONVERTER_PACKAGE
Default package where to find the converter.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ConverterUtil() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
convert(char[] chars)
Converts a array of char to an array of bytes.
|
static <T> T |
convert(Class<T> type,
Object toConvert)
Try to convert a value.
|
static void |
deregister()
To remove any registered converter.
|
static <T> org.apache.commons.beanutils.Converter |
getConverter(Class<T> type)
Try to find amatching converter for the given
type. |
static void |
initConverters()
To init default converters (using the service loader mecanism on contract
NuitonConverter). |
static void |
registerConverter(Class<?> type) |
protected static void |
registerConverter0(Class<?> type) |
static <E extends Enum> |
registerEnumConverter(Class<E> type)
Register a new converter for a given enum type,
not using any default value.
|
static <E extends Enum> |
registerEnumConverter(Class<E> type,
Object defaultValue)
Register a new converter for a given enum type,
using the given default value.
|
protected static final String CONVERTER_PACKAGE
public static <T> org.apache.commons.beanutils.Converter getConverter(Class<T> type)
type.
If required, init defaults converters (see initConverters()).
If not found and type is an enum, then will register a enum type converter.
If still not found, try to register a converter having the NuitonConverter contract named typeConverter
in the current package (CONVERTER_PACKAGE).
For example with type MyType, will try to find the converter org.nuiton.converter.MyTypeConverter.
T - type to converttype - type to convertnull if not foundpublic static <T> T convert(Class<T> type, Object toConvert)
Will first try to find a matching converter, if not found return then null.
Note: will init default converters or matching data type converter if required.
T - type of data to converttype - type of data to converttoConvert - data to convertnull if no converter found for the type of data.public static void registerConverter(Class<?> type) throws IllegalAccessException, InstantiationException, ClassNotFoundException
protected static void registerConverter0(Class<?> type) throws IllegalAccessException, InstantiationException, ClassNotFoundException
public static <E extends Enum> void registerEnumConverter(Class<E> type, Object defaultValue)
type - enum type to convertdefaultValue - default value to use.EnumConverterpublic static <E extends Enum> void registerEnumConverter(Class<E> type)
type - enum type to convertEnumConverterpublic static byte[] convert(char[] chars)
TODO Find out who uses this ?
chars - array of characters to converterpublic static void deregister()
At the next call to method convert(Class, Object) or getConverter(Class), default converters
will be registred again.
public static void initConverters()
NuitonConverter).
If was already init, then will do nothing.
Note: the getConverter(Class) or convert(Class, Object) methods always invoke this method if
the class was not initialized (see the wasInit internal flag).
Copyright © 2014–2018 CodeLutin. All rights reserved.