Package org.jboss.resteasy.util
Class TypeConverter
java.lang.Object
org.jboss.resteasy.util.TypeConverter
A utility class that can convert a String value as a typed object.
- Version:
- $Revision: $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
getBooleanValue
(String source) Returns a Boolean value from a String.static <T> T
A generic method that returns theString
as the specified Java type.private static <T> T
getTypeViaStringConstructor
(String source, Class<T> targetType) static <T> T
getTypeViaValueOfMethod
(String source, Class<T> targetType) static boolean
isConvertable
(Class<?> targetType) Tests if the class can safely be converted from a String to the specified type.
-
Field Details
-
VALUE_OF_METHOD
- See Also:
-
PRIMITIVES
A map of primitive to objects.
-
-
Constructor Details
-
TypeConverter
private TypeConverter()
-
-
Method Details
-
getType
A generic method that returns theString
as the specified Java type.- Type Parameters:
T
- the type to return- Parameters:
targetType
-source
- the string value to convert- Returns:
- the object instance
-
isConvertable
Tests if the class can safely be converted from a String to the specified type.- Parameters:
targetType
- the type to convert to- Returns:
- true if the class possesses either a "valueOf()" method or a constructor with a String parameter.
-
getBooleanValue
Returns a Boolean value from a String. Unlike
invalid @link
{@link Boolean.#valueOf(String)
- Yes
- Y
- T
- 1
While the following values will return false:
- No
- N
- F
- 0
- Parameters:
source
-- Returns:
-
getTypeViaValueOfMethod
public static <T> T getTypeViaValueOfMethod(String source, Class<T> targetType) throws NoSuchMethodException - Type Parameters:
T
-- Parameters:
source
-targetType
-- Returns:
- Throws:
NoSuchMethodException
-
getTypeViaStringConstructor
- Type Parameters:
T
-- Parameters:
source
-targetType
-- Returns:
- Throws:
IllegalArgumentException
InstantiationException
IllegalAccessException
InvocationTargetException
-