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 Details

    • decode

      @NotNull @NotNull dev.siroshun.jfun.result.Result<T,DecodeError> decode(@NotNull @NotNull In in)
      Decodes the data from the provided In.
      Parameters:
      in - the In for reading the data to decode
      Returns:
      a result containing the decoded data, or a DecodeError if 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.
      Type Parameters:
      A - the type of the mapped data
      Parameters:
      mapper - the Function to map the decoded data to another type
      Returns:
      a new Decoder that 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 the Result.
      Type Parameters:
      A - the type of the mapped data
      Parameters:
      mapper - the Function to map the decoded data to another type and returns a Result of the mapping
      Returns:
      a new Decoder that maps the decoded data to another type and flattens the Result
    • inspect

      @NotNull default @NotNull Decoder<T> inspect(@NotNull @NotNull Function<? super T,dev.siroshun.jfun.result.Result<T,DecodeError>> inspector)
      Inspects the decoded data.
      Parameters:
      inspector - the Function to inspect the decoded data and returns a Result of the inspection
      Returns:
      a new Decoder that 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 a DecodeError and returns a new Result.
      Parameters:
      onError - the Function to catch the DecodeError and returns a Result of the new Result
      Returns:
      a new Decoder that catches a DecodeError and returns a new Result
    • 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

      @NotNull default @NotNull Decoder<List<T>> toListDecoder()
      Creates a Decoder that decodes a List of Decoder.
      Returns:
      a Decoder that decodes a List of Decoder
    • toSetDecoder

      @NotNull default @NotNull Decoder<Set<T>> toSetDecoder()
      Creates a Decoder that decodes a Set of Decoder.

      This Decoder does not allow duplicates in the set.

      Returns:
      a Decoder that decodes a Set of Decoder
    • toSetDecoder

      @NotNull default @NotNull Decoder<Set<T>> toSetDecoder(boolean allowDuplicates)
      Creates a Decoder that decodes a Set of Decoder.
      Parameters:
      allowDuplicates - whether to allow duplicates in the set
      Returns:
      a Decoder that decodes a Set of Decoder