- Type Parameters:
C
- The type the encoder is for
- All Known Subinterfaces:
Codec<C>
,KeyableCodec<C>
,KeyableEncoder<C>
- All Known Implementing Classes:
EitherCodec
,ListCodec
,MapCodec
,NamedCodec
,OptionalCodec
,RangeCodec
,UnitCodec
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents an encoder for a specific type.
The implementation encodes a value of the type specified by the type provider
and returns a result containing the encoded value or an error message.
The implementation encodes a value of the type specified by the type provider
and returns a result containing the encoded value or an error message.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <R> R
encode
(@NotNull TypeProvider<R> provider, C value) Encodes the value of the specified type and returns the encoded value directly.default <R> R
encode
(@NotNull TypeProvider<R> provider, R current, C value) Encodes the value of the specified type and returns the encoded value directly.<R> @NotNull Result
<R> encodeStart
(@NotNull TypeProvider<R> provider, R current, C value) Encodes the value of the specified type and returns the result.
The result contains the encoded value or an error message.default <O> @NotNull Encoder
<O> mapEncoder
(@NotNull ResultingFunction<O, C> to) Maps the type of the encoded value to another type.
The mapping function is applied to the raw input value ofencodeStart(TypeProvider, Object, Object)
.
The mapping function returns a result containing the mapped value or an error message if the mapping process fails.
The mapping function is not allowed to throw any exceptions.
-
Method Details
-
encode
Encodes the value of the specified type and returns the encoded value directly.- Type Parameters:
R
- The type to encode to- Parameters:
provider
- The type providervalue
- The value to encode- Returns:
- The encoded value
- Throws:
NullPointerException
- If the type provider is nullEncoderException
- If an error occurs during encoding
-
encode
@NotNull default <R> R encode(@NotNull @NotNull TypeProvider<R> provider, @NotNull R current, @Nullable C value) Encodes the value of the specified type and returns the encoded value directly.
The current value is the value that is currently encoded.
In the most cases this value should be equal toTypeProvider.empty()
.
In the case of encoding a value that is part of a bigger structure, the current value should be the structure.
- Type Parameters:
R
- The type to encode to- Parameters:
provider
- The type providercurrent
- The current valuevalue
- The value to encode- Returns:
- The encoded value
- Throws:
NullPointerException
- If the type provider is nullEncoderException
- If an error occurs during encoding- See Also:
-
encodeStart
@NotNull <R> @NotNull Result<R> encodeStart(@NotNull @NotNull TypeProvider<R> provider, @NotNull R current, @Nullable C value) Encodes the value of the specified type and returns the result.
The result contains the encoded value or an error message.
The current value is the value that is currently encoded.
In the most cases this value should be equal toTypeProvider.empty()
.
In the case of encoding a value that is part of a bigger structure, the current value should be the structure.
- Type Parameters:
R
- The type to encode to- Parameters:
provider
- The type providercurrent
- The current valuevalue
- The value to encode- Returns:
- The result
- Throws:
NullPointerException
- If the type provider is null
-
mapEncoder
Maps the type of the encoded value to another type.
The mapping function is applied to the raw input value ofencodeStart(TypeProvider, Object, Object)
.
The mapping function returns a result containing the mapped value or an error message if the mapping process fails.
The mapping function is not allowed to throw any exceptions.- Type Parameters:
O
- The type to map to- Parameters:
to
- The mapping function- Returns:
- The mapped encoder
- Throws:
NullPointerException
- If the mapping function is null
-