Package org.axonframework.serialization
Class ChainedConverter<S,T>
java.lang.Object
org.axonframework.serialization.ChainedConverter<S,T>
- Type Parameters:
S- The source type of the converterT- The target type of the converter
- All Implemented Interfaces:
ContentTypeConverter<S,T>
A converter 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
- 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 a converter that can convert an IntermediateRepresentation from the givensourceTypeto the giventargetTypeusing a chain formed with 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.Converts the given object into another.The expected type of input data.The returned type of IntermediateRepresentation
-
Constructor Details
-
ChainedConverter
Creates a new instance that uses the givendelegatesto form a chain of converters. Note that thedelegatesmust for a Continuous chain, meaning that each item must produce an IntermediateRepresentation of a type that can be consumed by the next delegate. To automatically calculate a route between converters, seecalculateChain(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 a converter that can convert an IntermediateRepresentation from the givensourceTypeto the giventargetTypeusing a chain formed with givencandidates. The returned converter uses some (or all) of the givencandidatesas delegates.- Type Parameters:
S- The source type of the converterT- The target type of the converter- Parameters:
sourceType- The source type of the convertertargetType- The target type of the convertercandidates- The candidates to form a chain with- Returns:
- A converter for the given source and target types
- Throws:
CannotConvertBetweenTypesException- 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. Whentrue, it may use any number of the givenconvertersto form a chain.- Type Parameters:
S- The content type of the source objectT- The content type of the target object- Parameters:
sourceContentType- The content type of the source objecttargetContentType- The content type of the target objectconverters- The converters eligible for use- Returns:
trueif this Converter can convert between the given types, using the given converters. Otherwisefalse.
-
convert
Description copied from interface:ContentTypeConverterConverts the given object into another. Typically, these values are contained by aSerializedObjectinstance.- Specified by:
convertin interfaceContentTypeConverter<S,T> - Parameters:
original- the value to convert- Returns:
- the converted value
-
expectedSourceType
Description copied from interface:ContentTypeConverterThe expected type of input data.- Specified by:
expectedSourceTypein interfaceContentTypeConverter<S,T> - Returns:
- the expected data format in IntermediateRepresentation
-
targetType
Description copied from interface:ContentTypeConverterThe returned type of IntermediateRepresentation- Specified by:
targetTypein interfaceContentTypeConverter<S,T> - Returns:
- the output data format in IntermediateRepresentation
-