Interface Converter
- All Known Implementing Classes:
BasicConverter,CachingConverter,ConfigurableConverter,MarshallingContextConverter
Use BasicConverter.INSTANCE for a default singleton implementation that supports
a wide range of common type conversions without requiring a MarshallingContext or MarshallingSession.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanConvert(Class<?> inType, Class<?> outType) Returnstrue if this converter can convert from the specified input type to the specified output type.<T> TConverts the specified object to the specified type.default <T> Tto(Object o, Object memberOf, ConverterSession session, Class<T> type) Converts the specified object to the specified type, using the given outer instance and converter session.default <T> TConverts the specified object to the specified parameterized type, using the given outer instance and converter session.<T> TConverts the specified object to the specified parameterized type.
-
Method Details
-
canConvert
Returnstrue if this converter can convert from the specified input type to the specified output type.- Parameters:
inType- The input type.outType- The output type.- Returns:
true if a conversion path exists.
-
to
Converts the specified object to the specified type.When the input is
null , returns the JVM default for primitive types (e.g.0forint.class,falseforboolean.class), ornull for all other types. ThrowsInvalidConversionExceptionwhen no conversion path exists. UsecanConvert(Class, Class)to pre-check if uncertain.- Type Parameters:
T- The type to convert to.- Parameters:
o- The object to convert. Can benull .type- The type to convert to.- Returns:
- The converted object, the primitive zero-value if input is
null and type is primitive, ornull if the input isnull and type is non-primitive. - Throws:
InvalidConversionException- If no conversion path exists from the input type to the target type.
-
to
Converts the specified object to the specified parameterized type.This method allows conversion to complex parameterized types such as collections and maps. The
args parameter specifies the type parameters of the main type.Returns
null only when the input object isnull . ThrowsInvalidConversionExceptionwhen no conversion path exists.Example:
// Convert to List<String> List<String>list =converter .to(o , List.class , String.class );// Convert to Map<String,Integer> Map<String,Integer>map =converter .to(o , Map.class , String.class , Integer.class );- Type Parameters:
T- The type to convert to.- Parameters:
o- The object to convert. Can benull .mainType- The main type to convert to.args- The type parameters of the main type.- Returns:
- The converted object, or
null if the input isnull . - Throws:
InvalidConversionException- If no conversion path exists from the input type to the target type.
-
to
Converts the specified object to the specified type, using the given outer instance and converter session.The default implementation ignores both
memberOfandsessionand delegates toto(Object, Class). Override in subclasses that wish to thread these intoConversion.to(Object, Object, ConverterSession, Class[]).- Type Parameters:
T- The type to convert to.- Parameters:
o- The object to convert. Can benull .memberOf- The outer instance for non-static inner class construction, ornull .session- The converter session providing contextual objects, ornull .type- The type to convert to.- Returns:
- The converted object, or
null if the input isnull . - Throws:
InvalidConversionException- If no conversion path exists from the input type to the target type.
-
to
Converts the specified object to the specified parameterized type, using the given outer instance and converter session.The default implementation ignores both
memberOfandsessionand delegates toto(Object, Type, Type[]). Override in subclasses that wish to thread these intoConversion.to(Object, Object, ConverterSession, Class[]).- Type Parameters:
T- The type to convert to.- Parameters:
o- The object to convert. Can benull .memberOf- The outer instance for non-static inner class construction, ornull .session- The converter session providing contextual objects, ornull .mainType- The main type to convert to.args- The type parameters of the main type.- Returns:
- The converted object, or
null if the input isnull . - Throws:
InvalidConversionException- If no conversion path exists from the input type to the target type.
-