Class GenericConverter
- All Implemented Interfaces:
Converter
A simple implementation of the Converter interface that delegates to the default
BeanContext session for type conversion.
This converter provides a convenient way to convert objects between different types using the same conversion logic that's used throughout the Juneau framework.
Example:
Thread Safety:
This class is thread-safe. The singleton instance can be safely shared across multiple threads.
See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GenericConverterSingleton instance of the generic converter. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
INSTANCE
Singleton instance of the generic converter.This instance can be safely shared across multiple threads and reused for all conversion operations.
-
-
Constructor Details
-
GenericConverter
public GenericConverter()
-
-
Method Details
-
convertTo
Converts the specified object to the specified type.This method delegates to the default
BeanContextsession for the actual conversion logic. It supports all the same conversion types that are supported by the framework's bean conversion system.Supported conversions include:
- Primitive types and their wrapper classes
- String to Number conversions
- Map to Bean conversions
- Collection to Array conversions
- Enum conversions
- Object swap conversions
- And many more...
- Specified by:
convertToin interfaceConverter- Type Parameters:
T- The target type to convert to.- Parameters:
type- The target class type.o- The object to convert.- Returns:
- The converted object, or
null if the input object isnull . - Throws:
InvalidDataConversionException- If the object cannot be converted to the specified type.
-