Class MarshallingContextConverter
- All Implemented Interfaces:
Converter
A simple implementation of the Converter interface that delegates to the default
MarshallingContext 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 MarshallingContextConverterSingleton instance of the generic converter. -
Method Summary
Modifier and TypeMethodDescription<T> TConverts the specified object to the specified type.<T> Tto(Object o, Object memberOf, ConverterSession session, Class<T> type) Converts the specified object to the specified type, using the given outer instance for non-static inner class construction.<T> TConverts the specified object to the specified parameterized type, using the given outer instance for non-static inner class construction.<T> TConverts the specified object to the specified parameterized type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.conversion.Converter
canConvert
-
Field Details
-
INSTANCE
Singleton instance of the generic converter.This instance can be safely shared across multiple threads and reused for all conversion operations.
-
-
Method Details
-
to
Converts the specified object to the specified type.This method delegates to the default
MarshallingContextsession 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:
toin interfaceConverter- Type Parameters:
T- The target type to convert to.- Parameters:
o- The object to convert.type- The target class type.- Returns:
- The converted object, or
null if the input object isnull . - Throws:
InvalidDataConversionException- If the object cannot be converted to the specified type.
-
to
Converts the specified object to the specified parameterized type.This method delegates to the default
MarshallingContextsession for the actual conversion logic, supporting complex parameterized types such as collections and maps.- Specified by:
toin interfaceConverter- Type Parameters:
T- The target type to convert to.- Parameters:
o- The object to convert.mainType- The main type to convert to.args- The type parameters of the main type.- Returns:
- The converted object, or
null if the input object isnull . - Throws:
InvalidDataConversionException- If the object cannot be converted to the specified type.
-
to
Converts the specified object to the specified type, using the given outer instance for non-static inner class construction.- Specified by:
toin interfaceConverter- Type Parameters:
T- The target type to convert to.- Parameters:
o- The object to convert.memberOf- The outer instance for non-static inner class construction, ornull if the target is not a non-static inner member class.session- The converter session, ornull (ignored either way; this implementation does not use a converter session).type- The target class type.- Returns:
- The converted object, or
null if the input object isnull . - Throws:
InvalidDataConversionException- If the object cannot be converted to the specified type.
-
to
Converts the specified object to the specified parameterized type, using the given outer instance for non-static inner class construction.- Specified by:
toin interfaceConverter- Type Parameters:
T- The target type to convert to.- Parameters:
o- The object to convert.memberOf- The outer instance for non-static inner class construction, ornull if the target is not a non-static inner member class.session- The converter session, ornull (ignored either way; this implementation does not use a converter session).mainType- The main type to convert to.args- The type parameters of the main type.- Returns:
- The converted object, or
null if the input object isnull . - Throws:
InvalidDataConversionException- If the object cannot be converted to the specified type.
-