Package dev.siroshun.codec4j.api.encoder
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 Summary
Modifier and TypeMethodDescriptiondefault <A> @NotNull Encoder<A> Maps the input data to another type.<O> @NotNull dev.siroshun.jfun.result.Result<O, EncodeError> default <A> @NotNull Encoder<A> flatComap(@NotNull Function<? super A, ? extends dev.siroshun.jfun.result.Result<? extends T, EncodeError>> mapper) Maps the input data to another type and flattens theResult.default <O> @NotNull FieldEncoder<O> toFieldEncoder(@NotNull String fieldName, @NotNull Function<O, T> getter) default <O> @NotNull FieldEncoder<O> toFieldEncoder(@NotNull String fieldName, @NotNull Function<O, T> getter, @Nullable Predicate<O> canOmit)
-
Method Details
-
encode
@NotNull <O> @NotNull dev.siroshun.jfun.result.Result<O,EncodeError> encode(@NotNull @NotNull Out<O> out, @UnknownNullability T input) - Type Parameters:
O- the type of the output destination- Parameters:
out- theOutfor writing the encoded datainput- the input data to encode- Returns:
- a result containing the encoded data, or a
EncodeErrorif 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. -
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 theResult. -
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
- Type Parameters:
C- the type of the collection to encode- Returns:
- a new
ElementEncoderthat encodes the collection ofEncoderto anOut
-