Class CollectionCodec

java.lang.Object
dev.siroshun.codec4j.api.codec.collection.CollectionCodec

public final class CollectionCodec extends Object
A Codec for collections such as List and Set.
  • Method Details

    • list

      @NotNull public static <E> @NotNull Codec<List<E>> list(@NotNull @NotNull Codec<E> elementCodec)
      Creates a Codec for List with the specified element type CollectionCodec.
      Type Parameters:
      E - the type of the element
      Parameters:
      elementCodec - the Codec for elements
      Returns:
      a Codec
    • set

      @NotNull public static <E> @NotNull Codec<Set<E>> set(@NotNull @NotNull Codec<E> elementCodec)
      Creates a Codec for Set with the specified element type CollectionCodec.

      This Codec does not allow duplicates in the set when decoding.

      Type Parameters:
      E - the type of the element
      Parameters:
      elementCodec - the Codec for elements
      Returns:
      a Codec
    • set

      @NotNull public static <E> @NotNull Codec<Set<E>> set(@NotNull @NotNull Codec<E> elementCodec, boolean allowDuplicates)
      Creates a Codec for Set with the specified element type CollectionCodec.
      Type Parameters:
      E - the type of the element
      Parameters:
      elementCodec - the Codec for elements
      allowDuplicates - whether to allow duplicates in the set
      Returns:
      a Codec
    • collection

      @NotNull public static <E> @NotNull Codec<Collection<E>> collection(@NotNull @NotNull Codec<E> elementCodec)
      Creates a CollectionCodec for Collection with the specified element type CollectionCodec.
      Type Parameters:
      E - the type of the element
      Parameters:
      elementCodec - the Codec for elements
      Returns:
      a CollectionCodec