Component serialization
A serializer converts between Component and a text or binary format. Minestom registers service providers for Adventure's serializers, so the static accessors return instances configured for Minestom rather than the defaults. NbtComponentSerializer is Minestom's; the rest come from Adventure.
Plain text
PlainTextComponentSerializer.plainText() produces unformatted text, discarding all styling.
String plain = PlainTextComponentSerializer.plainText().serialize(component);Legacy
LegacyComponentSerializer reads and writes the color code format that predates components. legacySection() uses §, legacyAmpersand() uses &, and they are otherwise identical.
Component parsed = LegacyComponentSerializer.legacyAmpersand().deserialize("&cDanger");Legacy codes predate most component data. Round-tripping through this serializer downsamples RGB colors to the nearest of the sixteen named colors, and discards fonts, shadow colors, and hover and click events.
JSON
GsonComponentSerializer.gson() produces the chat JSON the vanilla client uses. Minestom configures it with an NBT-backed legacy hover event serializer, so pre-1.16 hover events deserialize correctly.
gsonLegacy() is the same with RGB output disabled, downsampling colors to the nearest named one, for clients and tools that predate 1.16.
Components are sent to the client as NBT rather than JSON. Use JSON for storage and for tools that read it.
NBT
NbtComponentSerializer.nbt() produces the NBT form components are sent in over the wire, and the form used in item and block NBT.
ANSI
ANSIComponentSerializer.ansi() produces terminal escape codes, for writing colored components to console output.
The flattener
The plain text, legacy, and ANSI serializers use Minestom's flattener to reduce a component tree to a flat string.
Automatic translation is disabled by default. When it is disabled, a TranslatableComponent produces no text when flattened, and the output contains no key. The flattener replaces Adventure's handler for translatable components with its own handler, which only runs when automatic translation is enabled. See Localization.
MiniMessage
ComponentSerializer<Component, Component, T> is the interface to implement for a custom format. A tag-based serializer is already available in MiniMessage:
Component component = MiniMessage.miniMessage().deserialize("<red>Hello <bold>there");It is not bundled with Minestom. Add net.kyori:adventure-text-minimessage to use it.
