public class DefaultTypeConverter extends DefaultTypeConverterProvider implements TypeConverter
This converter supports all the basic Java types plus types. Additionally it
supports any class that defines a static fromString(String) or
valueOf(String) method. Finally it supports any class that defines a
constructor that takes a string.
| Constructor and Description |
|---|
DefaultTypeConverter() |
DefaultTypeConverter(NumericTypeConverter numericConverter) |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArguments(String name,
Class<?> type,
String value)
Checks that the arguments are all non-null
|
Object |
convert(String name,
Class<?> type,
String value)
Convert a string value into an appropriately typed value
|
void |
setNumericConverter(NumericTypeConverter converter)
Sets the numeric type converter to use, if
null then default
behaviour of the type converter instance (whatever that might be) will be
used |
protected ConvertResult |
tryConvertBasicTypes(String name,
Class<?> type,
String value)
Tries to convert the value if it is one of the common Java types
|
protected ConvertResult |
tryConvertFromString(String name,
Class<?> type,
String value)
Tries to convert the value by invoking a static
fromString(String) method on the type |
protected ConvertResult |
tryConvertFromValueOf(String name,
Class<?> type,
String value)
Tries to convert the value by invoking a static
valueOf(String)
method on the type |
protected ConvertResult |
tryConvertStringConstructor(String name,
Class<?> type,
String value)
Tries to convert the value by invoking a constructor that takes a string
on the type
|
protected ConvertResult |
tryConvertStringMethod(String name,
Class<?> type,
String value,
String methodName)
Tries to convert the value by invoking a static method on the type
|
getTypeConverter, getTypeConverterpublic DefaultTypeConverter()
public DefaultTypeConverter(NumericTypeConverter numericConverter)
public Object convert(String name, Class<?> type, String value)
TypeConverterconvert in interface TypeConvertername - Option Nametype - Target Typevalue - String Valuepublic static void checkArguments(String name, Class<?> type, String value)
name - Option/Argument nametype - Target typevalue - String to convertprotected final ConvertResult tryConvertStringConstructor(String name, Class<?> type, String value)
type - Typevalue - valueprotected final ConvertResult tryConvertFromValueOf(String name, Class<?> type, String value)
valueOf(String)
method on the typetype - Typevalue - Valueprotected final ConvertResult tryConvertFromString(String name, Class<?> type, String value)
fromString(String) method on the typetype - Typevalue - Valueprotected final ConvertResult tryConvertStringMethod(String name, Class<?> type, String value, String methodName)
type - Typevalue - ValuemethodName - Name of the method to invokeprotected final ConvertResult tryConvertBasicTypes(String name, Class<?> type, String value)
type - Typevalue - Valuepublic void setNumericConverter(NumericTypeConverter converter)
TypeConverternull then default
behaviour of the type converter instance (whatever that might be) will be
usedsetNumericConverter in interface TypeConverterconverter - Numeric type converterCopyright © 2012–2022. All rights reserved.