Interface Caster<I,O>
- Type Parameters:
I
- the input type before castingO
- the output type after casting
- All Known Subinterfaces:
CasterChain<I,
O>
- All Known Implementing Classes:
DefaultCasterChain
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface representing a transformation from one stream of values to another, possibly adjusting for
version compatibility or format changes.
This interface is typically used to implement:
- Upcasting: Transforming older versions of serialized data to newer schema versions.
- Downcasting: Reducing an object’s structure to an earlier schema version.
The cast(Stream, Integer)
method may inspect the desired revision and apply transformation logic
accordingly.
Casters are often discovered and applied as part of a CasterChain
, which enables chaining and runtime
composition of multiple casting transformations.
-
Method Summary
Modifier and TypeMethodDescriptionCasts the given stream of input values to the output format using the default transformation rules.Casts the given stream of input values to the output format, optionally considering a target revision.default <BEFORE,
AFTER>
Caster<BEFORE, AFTER> Creates a newCaster
that applies preprocessing and postprocessing steps before and after the core cast.
-
Method Details
-
cast
Casts the given stream of input values to the output format using the default transformation rules. This is equivalent to callingcast(input, null)
.- Parameters:
input
- the input stream of values- Returns:
- a stream of transformed output values
-
cast
Casts the given stream of input values to the output format, optionally considering a target revision.- Parameters:
input
- the input stream of valuesdesiredRevision
- the target revision number (nullable)- Returns:
- a stream of transformed output values
-
intercept
default <BEFORE,AFTER> Caster<BEFORE,AFTER> intercept(Function<BEFORE, ? extends I> before, Function<? super O, AFTER> after) Creates a newCaster
that applies preprocessing and postprocessing steps before and after the core cast.- Type Parameters:
BEFORE
- the new input typeAFTER
- the new output type- Parameters:
before
- a function to transform input from typeBEFORE
toI
after
- a function to transform output fromO
toAFTER
- Returns:
- a composed
Caster
with adapted input/output types
-