Package org.axonframework.serialization
Class ChainingConverter
java.lang.Object
org.axonframework.serialization.ChainingConverter
- All Implemented Interfaces:
Converter
Converter implementation that will combine converters to form chains of converters to be able to convert
from one type to another, for which there is no suitable single converter.
This implementation will also autodetect ContentTypeConverter implementations by scanning
/META-INF/services/org.axonframework.serialization.ContentTypeConverter files on the classpath. These
files must contain the fully qualified class names of the implementations to use.- Since:
- 2.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize a new ChainingConverter with the context ClassLoader for this thread.ChainingConverter(ClassLoader classLoader) Initialize a new ChainingConverter. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanConvert(Class<?> sourceType, Class<?> targetType) Indicates whether this converter is capable of converting the givensourceTypeto thetargetType.<T> TConverts the given object into another using the source type to find the conversion path.Retrieves the list ofContentTypeConverterregistered in thisChainingConverterinstance.voidregisterConverter(Class<? extends ContentTypeConverter> converterType) Registers a convert of the givenconverterTypewith this factory, only if initialization of such a converter is possible.voidregisterConverter(ContentTypeConverter converter) Registers the givenconverterwith this factory.voidsetAdditionalConverters(List<ContentTypeConverter> additionalConverters) Setter for dependency injection frameworks that require property methods.
-
Constructor Details
-
ChainingConverter
public ChainingConverter()Initialize a new ChainingConverter with the context ClassLoader for this thread. Will autodetect all converters mentioned in/META-INF/services/org.axonframework.serialization.ContentTypeConverterfiles on the class path. Instances of ChainingConverter are safe for use in a multi-threaded environment, with exception of theregisterConverter(ContentTypeConverter)method. -
ChainingConverter
Initialize a new ChainingConverter. Will autodetect all converters mentioned in/META-INF/services/org.axonframework.serialization.ContentTypeConverterfiles on the class path. Instances of ChainingConverter are safe for use in a multi-threaded environment, with exception of theregisterConverter(ContentTypeConverter)method.- Parameters:
classLoader- the class loader used to load the converters
-
-
Method Details
-
canConvert
Description copied from interface:ConverterIndicates whether this converter is capable of converting the givensourceTypeto thetargetType.- Specified by:
canConvertin interfaceConverter- Parameters:
sourceType- The type of data to convert fromtargetType- The type of data to convert to- Returns:
trueif conversion is possible,falseotherwise
-
convert
Description copied from interface:ConverterConverts the given object into another using the source type to find the conversion path. -
registerConverter
Registers the givenconverterwith this factory. The converter which is registered last will be inspected first when finding a suitable converter for a given input and output type. An alternative to explicit converter registration (but without the ordering guarantees) is to create a file calledorg.axonframework.serialization.ContentTypeConverterin/META-INF/services/on the class path which contains the fully qualified class names of the converters, separated by newlines. These implementations must have a public no-arg constructor.- Parameters:
converter- the converter to register.
-
registerConverter
Registers a convert of the givenconverterTypewith this factory, only if initialization of such a converter is possible. Both the expected source type and target type classes are checked for availability on the class path. In contrast toregisterConverter(ContentTypeConverter), this method allows potentially unsafe (in terms of class dependencies) converters to be registered. The converter which is registered last will be inspected first when finding a suitable converter for a given input and output type. An alternative to explicit converter registration (but without the ordering guarantees) is to create a file calledorg.axonframework.serialization.ContentTypeConverterin/META-INF/services/on the class path which contains the fully qualified class names of the converters, separated by newlines. These implementations must have a public no-arg constructor.- Parameters:
converterType- the type of converter to register.
-
setAdditionalConverters
Setter for dependency injection frameworks that require property methods. This method is the same as callingregisterConverter(ContentTypeConverter)for each converter in the given list ofadditionalConverters.- Parameters:
additionalConverters- The converters to register with this factory
-
getContentTypeConverters
Retrieves the list ofContentTypeConverterregistered in thisChainingConverterinstance.- Returns:
- unmodified list of content type converters.
-