Package com.twelvemonkeys.util.convert
Class DefaultConverter
java.lang.Object
com.twelvemonkeys.util.convert.DefaultConverter
- All Implemented Interfaces:
PropertyConverter
Converts strings to objects and back.
This converter first tries to create an object, using the class' single
string argument constructor (<type>(String)
) if found,
otherwise, an attempt to call
the class' static valueOf(String)
method. If both fails, a
ConversionException
is thrown.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/DefaultConverter.java#2 $
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate String
arrayToString
(Object[] pArray, String pFormat) private Object
Converts the string to an object of the given type.private Object[]
toObjectArray
(Object pObject) Converts the object to a string, usingpObject.toString()
.private Class
<?>
-
Constructor Details
-
DefaultConverter
public DefaultConverter()Creates aDefaultConverter
.
-
-
Method Details
-
toObject
Converts the string to an object of the given type.- Specified by:
toObject
in interfacePropertyConverter
- Parameters:
pString
- the string to convertpType
- the type to convert topFormat
- ignored.- Returns:
- the object created from the given string.
- Throws:
ConversionException
- if the type is null, or if the string cannot be converted into the given type, using a string constructor or staticvalueOf
method.
-
toArray
-
toString
Converts the object to a string, usingpObject.toString()
.- Specified by:
toString
in interfacePropertyConverter
- Parameters:
pObject
- the object to convert.pFormat
- ignored.- Returns:
- the string representation of the object, or
null
ifpObject == null
- Throws:
ConversionException
- if the string could not be converted to the specified type and format.
-
arrayToString
-
toObjectArray
-
unBoxType
-