Package org.axonframework.conversion
Class ChainedConverter<S,T>
java.lang.Object
org.axonframework.conversion.ChainedConverter<S,T>
- Type Parameters:
S- The source type of the converter.T- The target type of the converter.
- All Implemented Interfaces:
ContentTypeConverter<S,T>
A
ContentTypeConverter implementation that delegates to a chain of other ContentTypeConverters to
convert from a source to a target for which there is not necessarily a single converter available.- Since:
- 2.0.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionChainedConverter(List<ContentTypeConverter<?, ?>> delegates) Creates a new instance that uses the givendelegatesto form a chain of converters. -
Method Summary
Modifier and TypeMethodDescriptionstatic <S,T> ChainedConverter <S, T> calculateChain(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?, ?>> candidates) Returns aChainedConverterthat can convert an object from the givensourceTypeto the giventargetTypeusing a chain formed with the givencandidates.static <S,T> boolean canConvert(Class<S> sourceContentType, Class<T> targetContentType, List<ContentTypeConverter<?, ?>> converters) Indicates whether this converter is capable of converting the givensourceContentTypeintotargetContentType, using the givenconverters.@Nullable TConverts the giveninputobject of generic typeSinto an object of generic typeT.Returns the expected type of input data for thisContentTypeConvertertoContentTypeConverter.convert(Object).Returns the type of output for thisContentTypeConvertertoContentTypeConverter.convert(Object)into.
-
Constructor Details
-
ChainedConverter
Creates a new instance that uses the givendelegatesto form a chain of converters.Note that the
To automatically calculate a route between converters, seedelegatesmust for a continuous chain, meaning that each item must produce an object of a type that can be consumed by the next delegate.calculateChain(source, target, candidates)- Parameters:
delegates- The chain of delegates to perform the conversion.
-
-
Method Details
-
calculateChain
public static <S,T> ChainedConverter<S,T> calculateChain(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?, ?>> candidates) Returns aChainedConverterthat can convert an object from the givensourceTypeto the giventargetTypeusing a chain formed with the givencandidates.The returned converter uses some, or all, of the given
candidatesas delegates.- Type Parameters:
S- The source type of the converter.T- The target type of the converter.- Parameters:
sourceType- The source type of the converter.targetType- The target type of the converter.candidates- The candidates to form a chain with.- Returns:
- A converter for the given source and target types.
- Throws:
ConversionException- if no converter can be created using given candidates.
-
canConvert
public static <S,T> boolean canConvert(Class<S> sourceContentType, Class<T> targetContentType, List<ContentTypeConverter<?, ?>> converters) Indicates whether this converter is capable of converting the givensourceContentTypeintotargetContentType, using the givenconverters.When
true, it may use any number of the givenconvertersto form a chain.- Type Parameters:
S- The content type of the source object.T- The content type of the target object.- Parameters:
sourceContentType- The content type of the source object.targetContentType- The content type of the target object.converters- The converters eligible for use.- Returns:
trueif thisChainedConvertercan convert between the givensourceContentTypeandtargetContentType, using the givenconverters, Otherwisefalse.
-
expectedSourceType
Description copied from interface:ContentTypeConverterReturns the expected type of input data for thisContentTypeConvertertoContentTypeConverter.convert(Object).- Specified by:
expectedSourceTypein interfaceContentTypeConverter<S,T> - Returns:
- The expected type of input data for this
ContentTypeConvertertoContentTypeConverter.convert(Object).
-
targetType
Description copied from interface:ContentTypeConverterReturns the type of output for thisContentTypeConvertertoContentTypeConverter.convert(Object)into.- Specified by:
targetTypein interfaceContentTypeConverter<S,T> - Returns:
- The type of output for this
ContentTypeConvertertoContentTypeConverter.convert(Object)into.
-
convert
Description copied from interface:ContentTypeConverterConverts the giveninputobject of generic typeSinto an object of generic typeT.- Specified by:
convertin interfaceContentTypeConverter<S,T> - Parameters:
input- The object of generic typeSto convert into an object of generic typeT.- Returns:
- The converted version of the given
inputin typeT.
-