Interface Codec<T extends @UnknownNullability Object>

Type Parameters:
T - The type to be represented by this codec, nullable T will provide nullable results.
All Superinterfaces:
Decoder<T>, Encoder<T>
All Known Subinterfaces:
DataComponent<T>, StructCodec<R>

public interface Codec<T extends @UnknownNullability Object> extends Encoder<T>, Decoder<T>

A Codec represents a combined Encoder and Decoder for a value. Enabling easy encoding and decoding of values to and from a between formats, making serialization simple, reusable and type safe. Going between formats is handled by Transcoder.

Most of the primitive or commonly used codecs are provided as static fields in this interface. For example, INT is a codec for integers, and STRING is a codec for strings. You can even use Enum(Class) for enums, which will convert the enum to a string representation and back.

Codecs are immutable, you must chain methods to create a codec that you want. For example

         Codec<@Nullable String> codec = Codec.STRING.optional()
         Codec<Set<@Nullable String>> setCodec = codec.set();
     
 

Heavily inspired by Mojang/DataFixerUpper, licensed under the MIT license.