Class ChainingConverter
- java.lang.Object
-
- io.axoniq.dataprotection.serialization.ChainingConverter
-
- All Implemented Interfaces:
Converter
public class ChainingConverter extends Object implements 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/io.axoniq.dataprotection.serialization.ContentTypeConverterfiles 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
Constructors Constructor Description ChainingConverter()Initialize a new ChainingConverter with the context ClassLoader for this thread.ChainingConverter(ClassLoader classLoader)Initialize a new ChainingConverter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanConvert(Class<?> sourceType, Class<?> targetType)Indicates whether this converter is capable of converting the givensourceTypeto thetargetType.<T> Tconvert(Object original, Class<?> sourceType, Class<T> targetType)Converts the given object into another using the source type to find the conversion path.voidregisterConverter(ContentTypeConverter converter)Registers the givenconverterwith this factory.voidregisterConverter(Class<? extends ContentTypeConverter> converterType)Registers a convert of the givenconverterTypewith this factory, only if initialization of such a converter is possible.voidsetAdditionalConverters(List<ContentTypeConverter> additionalConverters)Setter for dependency injection frameworks that require property methods.
-
-
-
Constructor Detail
-
ChainingConverter
public ChainingConverter()
Initialize a new ChainingConverter with the context ClassLoader for this thread. Will autodetect all converters mentioned in/META-INF/services/io.axoniq.dataprotection.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
public ChainingConverter(ClassLoader classLoader)
Initialize a new ChainingConverter. Will autodetect all converters mentioned in/META-INF/services/io.axoniq.dataprotection.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 Detail
-
canConvert
public boolean canConvert(Class<?> sourceType, Class<?> targetType)
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
public <T> T convert(Object original, Class<?> sourceType, Class<T> targetType)
Description copied from interface:ConverterConverts the given object into another using the source type to find the conversion path.
-
registerConverter
public void registerConverter(ContentTypeConverter converter)
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 calledio.axoniq.dataprotection.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
public void registerConverter(Class<? extends ContentTypeConverter> converterType)
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 calledio.axoniq.dataprotection.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
public void setAdditionalConverters(List<ContentTypeConverter> additionalConverters)
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
-
-