Interface Encoder<T>

Type Parameters:
T - the type of the input data to encode
All Known Subinterfaces:
Codec<T>, ElementEncoder<E,T>, EntryEncoder<E,T>
All Known Implementing Classes:
MapCodec, ObjectEncoder

public interface Encoder<T>
An interface for encoding data to an Out.
  • Method Details

    • encode

      @NotNull <O> @NotNull dev.siroshun.jfun.result.Result<O,EncodeError> encode(@NotNull @NotNull Out<O> out, @UnknownNullability T input)
      Encodes the data from the provided Encoder to the provided Out.
      Type Parameters:
      O - the type of the output destination
      Parameters:
      out - the Out for writing the encoded data
      input - the input data to encode
      Returns:
      a result containing the encoded data, or a EncodeError if the operation failed
    • comap

      @NotNull default <A> @NotNull Encoder<A> comap(@NotNull @NotNull Function<? super A,? extends T> mapper)
      Maps the input data to another type.
      Type Parameters:
      A - the type of the mapped data
      Parameters:
      mapper - the Function to map the input data to another type
      Returns:
      a new Encoder that maps the input data to another type
    • flatComap

      @NotNull default <A> @NotNull Encoder<A> flatComap(@NotNull @NotNull Function<? super A,? extends dev.siroshun.jfun.result.Result<? extends T,EncodeError>> mapper)
      Maps the input data to another type and flattens the Result.
      Type Parameters:
      A - the type of the mapped data
      Parameters:
      mapper - the Function to map the input data to another type and returns a Result of the mapping
      Returns:
      a new Encoder that maps the input data to another type and flattens the Result
    • toFieldEncoder

      @Contract("_, _ -> new") @NotNull default <O> @NotNull FieldEncoder<O> toFieldEncoder(@NotNull @NotNull String fieldName, @NotNull @NotNull Function<O,T> getter)
    • toFieldEncoder

      @Contract("_, _, _ -> new") @NotNull default <O> @NotNull FieldEncoder<O> toFieldEncoder(@NotNull @NotNull String fieldName, @NotNull @NotNull Function<O,T> getter, @Nullable @Nullable Predicate<O> canOmit)
    • toCollectionEncoder

      @NotNull default <C extends Iterable<T>> @NotNull Encoder<C> toCollectionEncoder()
      Creates a new ElementEncoder that encodes the collection of Encoder to an Out.
      Type Parameters:
      C - the type of the collection to encode
      Returns:
      a new ElementEncoder that encodes the collection of Encoder to an Out