Module net.minestom.server
Package net.minestom.server.codec
@NotNullByDefault
package net.minestom.server.codec
Codecs are ways of expressing objects in intermediary formats.
The core abstraction is the
Transcoder
interface,
which supports multiple formats such as NBT, JSON and Java objects.
Codecs define conversion logic for individual types, while transcoders handle the representation and construction of data structures like lists and maps. This design allows super extensible, and type-safe serialization and deserialization across different data backends.
The codec system is built on codecs, where multiple codecs can be combined into a StructCodec
to represent complex data structures. Each codec can be used to encode and decode values in
various formats, such as JSON or NBT, using the Transcoder
interface.
See Transcoder
for format details and available implementations.
record MyType(int id, @Nullable String name) {
static final StructCodec<MyType> CODEC = StructCodec.struct(
"id", Codec.INT, MyType::id,
"name", Codec.STRING.optional(), MyType::name,
MyType::new
);
}
MyType value = new MyType(42, "Example"); // Or use a null name for no name.
// Encoding to JSON
JsonElement encoded = MyType.CODEC.encode(Transcoder.JSON, value).orElseThrow();
// Decoding from JSON
MyType decoded = MyType.CODEC.decode(Transcoder.JSON, encoded).orElseThrow();
-
ClassDescriptionA raw value wrapper for entry is an object combined with its current decoder.Used internally to hold component codecsResult.Error<T>Represents the
Result
was a failure.Represents theResult
was successful.StructCodec<R>A struct codec is a map backedCodec
, where the keys are strings.Transcoder<D>Transcoders are responsible for converting "primitive" java objects into their respectiveTranscoder
types.List builders are used to eventually build a list.Map builders are used to eventually build a map
They are considered mutable containers, but provide builder semantics.Represents an immutableMap
like object.Proxies all transcoder calls to the given delegate.