Pages: Serialization

Serialization

SporeAPI can turn common Minecraft objects into strings and back, so you can easily save them to a config or database. Location, ItemStack, and Inventory are supported out of the box.

val saved = SporeSerializer.serialize(player.location)
val loaded = SporeSerializer.deserialize(saved, Location::class.java)

For anything else, it just falls back to normal JSON, so it works with most of your own data classes too. If you want full control over how a type is saved, you can register your own codec with SporeCodecRegistry.register(MyType::class.java, MyCodec()).