Codecs
Creating a Codec for NamespacedKey
Codec<NamespacedKey> CODEC = Codecs.STRING.xmap(NamespacedKey::fromString, NamespacedKey::toString)
Then you would simply call CODEC.serialize(DynamicOps, key) for serialization and CODEC.deserialize(DynamicOps, data) for deserialization (data must be correct type, e.g for YamlOps it is Map<String, Object>)
Setting up Codec for a record with 3 vars
public record Example(String name, int age, float money) {
public static final Codec<Exmaple> CODEC = RecordCodecBuilder.create(
Codecs.STRING.fieldOf("name", Example::name),
Codecs.INT.fieldOf("age", Example::age),
Codecs.FLOAT.fieldOf("money", Example::money),
Example::new
);
}
Then simply call as was shown for NamespacedKey to serialize/deserialize.
23 November 2025