Class DefaultCasterChain<T,S extends SerializedObject<T>>
java.lang.Object
io.fluxcapacitor.javaclient.common.serialization.casting.DefaultCasterChain<T,S>
- Type Parameters:
T
- the data type of the serialized value (e.g. byte[] or JsonNode)S
- the serialized object wrapper containing the data
- All Implemented Interfaces:
Caster<S,
,S> CasterChain<S,
S>
public class DefaultCasterChain<T,S extends SerializedObject<T>>
extends Object
implements CasterChain<S,S>
Default implementation of the
CasterChain
interface used for managing and applying casting operations—
typically upcasting or downcasting—on SerializedObject
instances.
This class supports flexible runtime registration and execution of type transformers based on annotations such as
Upcast
and Downcast
. It allows the system to evolve serialized object schemas over time while
maintaining backward and forward compatibility.
Key Responsibilities
- Applies registered caster functions based on a combination of object type and revision.
- Supports both upcasting (increasing version) and downcasting (lowering version) based on configuration.
- Provides utility methods to create upcasters and downcasters using optional format conversion logic.
- Allows chaining via
intercept()
for use withConvertingSerializedObject
wrappers.
Usage
CasterChain<SerializedObject<byte[]>, SerializedObject<?>> upcaster =
DefaultCasterChain.createUpcaster(candidates, JsonNode.class);
Stream<SerializedObject<byte[]>> transformed = upcaster.cast(inputStream, latestRevision);
Design Notes
- Backed by a
Map<DataRevision, AnnotatedCaster<T>>
which ensures casting operations are deterministic. - When multiple methods would match the same revision, an exception is thrown to prevent ambiguous resolution.
- Supports optional format conversion using a
Converter
viaDefaultCasterChain.ConvertingSerializedObject
wrapper.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
ASerializedObject
wrapper that applies aConverter
to translate data from one format to another.protected static class
Represents a unique combination of serialized objecttype
andrevision
, used as a key in the caster registry. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DefaultCasterChain
(Collection<?> casterCandidates, Class<T> dataType, boolean down) -
Method Summary
Modifier and TypeMethodDescriptionCasts the given stream of input values to the output format, optionally considering a target revision.protected static <BEFORE,
INTERNAL>
CasterChain<SerializedObject<BEFORE>, SerializedObject<?>> create
(Collection<?> casterCandidates, Converter<BEFORE, INTERNAL> converter, boolean down) protected static <T,
S extends SerializedObject<T>>
CasterChain<S, S> create
(Collection<?> casterCandidates, Class<T> dataType, boolean down) static <T,
S extends SerializedObject<T>>
CasterChain<S, S> createDowncaster
(Collection<?> casterCandidates, Class<T> dataType) static <BEFORE,
INTERNAL>
CasterChain<SerializedObject<BEFORE>, SerializedObject<?>> createUpcaster
(Collection<?> casterCandidates, Converter<BEFORE, INTERNAL> converter) static <T,
S extends SerializedObject<T>>
CasterChain<S, S> createUpcaster
(Collection<?> casterCandidates, Class<T> dataType) registerCasterCandidates
(Object... candidates) Registers one or more objects that may contain casting logic (e.g. annotated methods or implementations).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.common.serialization.casting.Caster
cast
Methods inherited from interface io.fluxcapacitor.javaclient.common.serialization.casting.CasterChain
intercept
-
Constructor Details
-
DefaultCasterChain
-
-
Method Details
-
createUpcaster
public static <BEFORE,INTERNAL> CasterChain<SerializedObject<BEFORE>,SerializedObject<?>> createUpcaster(Collection<?> casterCandidates, Converter<BEFORE, INTERNAL> converter) -
createUpcaster
public static <T,S extends SerializedObject<T>> CasterChain<S,S> createUpcaster(Collection<?> casterCandidates, Class<T> dataType) -
createDowncaster
public static <T,S extends SerializedObject<T>> CasterChain<S,S> createDowncaster(Collection<?> casterCandidates, Class<T> dataType) -
create
protected static <BEFORE,INTERNAL> CasterChain<SerializedObject<BEFORE>,SerializedObject<?>> create(Collection<?> casterCandidates, Converter<BEFORE, INTERNAL> converter, boolean down) -
create
protected static <T,S extends SerializedObject<T>> CasterChain<S,S> create(Collection<?> casterCandidates, Class<T> dataType, boolean down) -
registerCasterCandidates
Description copied from interface:CasterChain
Registers one or more objects that may contain casting logic (e.g. annotated methods or implementations). These candidates are inspected and included into the chain if applicable.- Specified by:
registerCasterCandidates
in interfaceCasterChain<T,
S extends SerializedObject<T>> - Parameters:
candidates
- one or more caster providers- Returns:
- a
Registration
that can be used to remove the registered casters
-
cast
Description copied from interface:Caster
Casts the given stream of input values to the output format, optionally considering a target revision.
-