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 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.registerCasterCandidates(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
-
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.
-