Interface CasterChain<I,O>
- Type Parameters:
I- the input typeO- the output type
- All Superinterfaces:
Caster<I,O>
- All Known Implementing Classes:
DefaultCasterChain
A composite
Caster that supports registration of multiple casting strategies.
This interface allows dynamic addition of Caster instances, which may be applied in sequence or based on
type matching logic. CasterChains are used in serialization and deserialization pipelines to handle
transformations like upcasting, downcasting, or schema evolution.
It extends Caster and adds registration capabilities.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancanSkipCast(I input, Integer rev) Whether this chain is guaranteed to return the input as one unchanged logical value.default OcastFirstOrNull(I input, Integer rev) Casts a single input and returns the first resulting output, ornullif the input is dropped.default <BEFORE,AFTER>
CasterChain<BEFORE, AFTER> Composes this caster chain with input and output interceptors.default IprepareForSkippingCast(I input, Integer rev) Prepares an input for direct deserialization when no content caster can transform, split or drop it.io.fluxzero.common.RegistrationregisterCasterCandidates(Object... candidates) Registers one or more objects that may contain casting logic (e.g. annotated methods or implementations).
-
Method Details
-
castFirstOrNull
Casts a single input and returns the first resulting output, ornullif the input is dropped.This is equivalent to
cast(Stream.of(input), rev).findAny().orElse(null), but implementations may optimize the common no-caster path without constructing a stream pipeline.- Parameters:
input- the input valuerev- the target revision number (nullable)- Returns:
- the first casted result, or
nullwhen no result is produced
-
canSkipCast
-
prepareForSkippingCast
Prepares an input for direct deserialization when no content caster can transform, split or drop it. Implementations may normalize its type identifier, but must not execute content casters or converters.Returns the prepared input, or
nullwhen the ordinary casting path is required. The default is deliberately conservative, including for intercepted chains whose callbacks may transform their input.- Parameters:
input- the input valuerev- the target revision number (nullable)- Returns:
- the input with any required type normalization, or
nullif casting cannot safely be skipped
-
registerCasterCandidates
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.- Parameters:
candidates- one or more caster providers- Returns:
- a
Registrationthat can be used to remove the registered casters
-
intercept
default <BEFORE,AFTER> CasterChain<BEFORE,AFTER> intercept(Function<BEFORE, ? extends I> before, Function<? super O, AFTER> after) Composes this caster chain with input and output interceptors. Allows pre- and post-processing transformations around the casting logic.
-