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 with ConvertingSerializedObject 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 via DefaultCasterChain.ConvertingSerializedObject wrapper.
See Also: