Interface GsonComponentSerializer

All Superinterfaces:
ComponentDecoder<String, Component>, ComponentEncoder<Component, String>, ComponentSerializer<Component, Component, String>, JSONComponentSerializer

public interface GsonComponentSerializer extends JSONComponentSerializer
A gson component serializer.

This is a specific implementation of JSONComponentSerializer for the Gson library. Libraries that want to remain unopinionated should work with that interface instead.

Use colorDownsamplingGson() to support platforms that do not understand hex colors that were introduced in Minecraft 1.16.

Since:
4.0.0
  • Method Details

    • gson

      static GsonComponentSerializer gson()
      Gets a component serializer for gson serialization and deserialization.
      Returns:
      a gson component serializer
      Since:
      4.0.0
    • colorDownsamplingGson

      static GsonComponentSerializer colorDownsamplingGson()
      Gets a component serializer for gson serialization and deserialization.

      Hex colors are coerced to the nearest named color, and legacy hover events are emitted for action HoverEvent.Action.SHOW_TEXT.

      Returns:
      a gson component serializer
      Since:
      4.0.0
    • builder

      Returns:
      a builder
      Since:
      4.0.0
    • serializer

      com.google.gson.Gson serializer()
      Gets the underlying gson serializer.
      Returns:
      a gson serializer
      Since:
      4.0.0
    • populator

      UnaryOperator<com.google.gson.GsonBuilder> populator()
      Gets the underlying gson populator.
      Returns:
      a gson populator
      Since:
      4.0.0
    • deserializeFromTree

      Component deserializeFromTree(com.google.gson.JsonElement input)
      Deserialize a component from input of type JsonElement.
      Parameters:
      input - the input
      Returns:
      the component
      Since:
      4.7.0
    • serializeToTree

      com.google.gson.JsonElement serializeToTree(Component component)
      Deserialize a component to output of type JsonElement.
      Parameters:
      component - the component
      Returns:
      the json element
      Since:
      4.7.0
    • toBuilder

      Creates a new builder from this serializer.
      Returns:
      the builder
      Since:
      4.0.0