Danger

The Adventure docs are currently a work in progress. Some areas may have limited coverage or may not be entirely up to date. Feel free to join our discord at https://discord.gg/MMfhJ8F if you have any questions.

Text Serializers

The lowest-level way to convert between Adventure’s data and other formats are serializers. Some serializers convert to standard formats, while others convert to Adventure’s own formats.

Serializers

Components can be converted using any of these serializers:

// Creates a text component
final TextComponent textComponent = TextComponent.of("Hello ")
  .color(NamedTextColor.GOLD)
  .append(
    TextComponent.of("world")
      .color(NamedTextColor.AQUA).
      decoration(TextDecoration.BOLD, true)
  )
  .append(TextComponent.of("!").color(NamedTextColor.RED));

// Converts textComponent to the JSON form used for serialization by Minecraft.
String json = GsonComponentSerializer.gson().serialize(textComponent);

// Converts textComponent to a legacy string - "&6Hello &b&lworld&c!"
String legacy = LegacyComponentSerializer.legacyAmpersand().serialize(textComponent);

// Converts textComponent to a plain string - "Hello world!"
String plain = PlainComponentSerializer.INSTANCE.serialize(textComponent);

The same is of course also possible in reverse for deserialization.

// Converts JSON in the form used for serialization by Minecraft to a Component
Component component = GsonComponentSerializer.gson().deserialize(json);

// Converts a legacy string (using formatting codes) to a TextComponent
TextComponent component = LegacyComponentSerializer.legacyAmpersand().deserialize("&6Hello &b&lworld&c!");

// Converts a plain string to a TextComponent
TextComponent component = PlainComponentSerializer.INSTANCE.deserialize("Hello world!");