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, getTypeConverter
public DefaultTypeConverter()
public DefaultTypeConverter(NumericTypeConverter numericConverter)
public Object convert(String name, Class<?> type, String value)
TypeConverter
convert
in interface TypeConverter
name
- 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)
TypeConverter
null
then default
behaviour of the type converter instance (whatever that might be) will be
usedsetNumericConverter
in interface TypeConverter
converter
- Numeric type converterCopyright © 2012–2017. All rights reserved.