Package dev.siroshun.codec4j.api.decoder
Interface Decoder<T>
- Type Parameters:
T- the type of the decoded data
- All Known Subinterfaces:
Codec<T>,ElementDecoder<E,,R> EntryDecoder<K,V, R>
- All Known Implementing Classes:
MapCodec,ObjectDecoder
public interface Decoder<T>
An interface for decoding data from an
In.-
Method Summary
Modifier and TypeMethodDescriptioncatchError(@NotNull Function<? super DecodeError, dev.siroshun.jfun.result.Result<T, DecodeError>> onError) Catches aDecodeErrorand returns a newResult.@NotNull dev.siroshun.jfun.result.Result<T, DecodeError> Decodes the data from the providedIn.default <A> @NotNull Decoder<A> flatMap(@NotNull Function<? super T, dev.siroshun.jfun.result.Result<A, DecodeError>> mapper) Maps the decoded data to another type and flattens theResult.inspect(@NotNull Function<? super T, dev.siroshun.jfun.result.Result<T, DecodeError>> inspector) Inspects the decoded data.default <A> @NotNull Decoder<A> Maps the decoded data to another type.default @NotNull FieldDecoder<T> toOptionalFieldDecoder(@NotNull String fieldName, @UnknownNullability T defaultValue) default @NotNull FieldDecoder<T> toRequiredFieldDecoder(@NotNull String fieldName) toSetDecoder(boolean allowDuplicates) default @NotNull FieldDecoder<T> toSupplyingFieldDecoder(@NotNull String fieldName, @NotNull Supplier<T> defaultValueSupplier)
-
Method Details
-
decode
Decodes the data from the providedIn.- Parameters:
in- theInfor reading the data to decode- Returns:
- a result containing the decoded data, or a
DecodeErrorif the operation failed
-
map
@NotNull default <A> @NotNull Decoder<A> map(@NotNull @NotNull Function<? super T, ? extends A> mapper) Maps the decoded data to another type. -
flatMap
@NotNull default <A> @NotNull Decoder<A> flatMap(@NotNull @NotNull Function<? super T, dev.siroshun.jfun.result.Result<A, DecodeError>> mapper) Maps the decoded data to another type and flattens theResult. -
inspect
@NotNull default @NotNull Decoder<T> inspect(@NotNull @NotNull Function<? super T, dev.siroshun.jfun.result.Result<T, DecodeError>> inspector) Inspects the decoded data. -
catchError
@NotNull default @NotNull Decoder<T> catchError(@NotNull @NotNull Function<? super DecodeError, dev.siroshun.jfun.result.Result<T, DecodeError>> onError) Catches aDecodeErrorand returns a newResult.- Parameters:
onError- theFunctionto catch theDecodeErrorand returns aResultof the newResult- Returns:
- a new
Decoderthat catches aDecodeErrorand returns a newResult
-
toRequiredFieldDecoder
@NotNull default @NotNull FieldDecoder<T> toRequiredFieldDecoder(@NotNull @NotNull String fieldName) -
toOptionalFieldDecoder
@NotNull default @NotNull FieldDecoder<T> toOptionalFieldDecoder(@NotNull @NotNull String fieldName, @UnknownNullability T defaultValue) -
toSupplyingFieldDecoder
@NotNull default @NotNull FieldDecoder<T> toSupplyingFieldDecoder(@NotNull @NotNull String fieldName, @NotNull @NotNull Supplier<T> defaultValueSupplier) -
toListDecoder
-
toSetDecoder
-
toSetDecoder
-