Class ArrayCodec<T>

java.lang.Object
com.hypixel.hytale.codec.codecs.array.ArrayCodec<T>
All Implemented Interfaces:
Codec<T[]>, RawJsonCodec<T[]>, SchemaConvertable<T[]>, WrappedCodec<T>

public class ArrayCodec<T> extends Object implements Codec<T[]>, RawJsonCodec<T[]>, WrappedCodec<T>
Since:
30/6/17.
Version:
1.0
  • Constructor Details

  • Method Details

    • getChildCodec

      public Codec<T> getChildCodec()
      Specified by:
      getChildCodec in interface WrappedCodec<T>
    • decode

      public T[] decode(@Nonnull org.bson.BsonValue bsonValue, @Nonnull ExtraInfo extraInfo)
      Specified by:
      decode in interface Codec<T>
    • encode

      @Nonnull public org.bson.BsonValue encode(@Nonnull T[] array, ExtraInfo extraInfo)
      Specified by:
      encode in interface Codec<T>
    • decodeJson

      public T[] decodeJson(@Nonnull RawJsonReader reader, @Nonnull ExtraInfo extraInfo) throws IOException
      Specified by:
      decodeJson in interface Codec<T>
      Specified by:
      decodeJson in interface RawJsonCodec<T>
      Throws:
      IOException
    • metadata

      @Nonnull public ArrayCodec<T> metadata(Metadata metadata)
    • toSchema

      @Nonnull public Schema toSchema(@Nonnull SchemaContext context)
      Description copied from interface: SchemaConvertable
      Returns a schema object that represents this codec as JSON Schema.
      Specified by:
      toSchema in interface SchemaConvertable<T>
      Parameters:
      context - A context to use to assist with creating the schema.
      Returns:
      the generated schema.
    • getDefaultSupplier

      @Nullable public Supplier<T> getDefaultSupplier()
    • ofBuilderCodec

      @Nonnull public static <T> ArrayCodec<T> ofBuilderCodec(@Nonnull BuilderCodec<T> codec, IntFunction<T[]> arrayConstructor)
      Construct an ArrayCodec from the given BuilderCodec whose default array element value is taken from BuilderCodec.getSupplier(). The returned Codec will parse null array elements as the BuilderCodec's default value.
      Type Parameters:
      T - The array element type.
      Parameters:
      codec - The BuilderCodec to construct an ArrayCodec for.
      arrayConstructor - An IntFunction used to construct arrays of element type T.
      Returns:
      A new ArrayCodec for encoding and decoding arrays of type T.