Skip to content

GsonComponentSerializer should allow the payload to be an BinaryTag #1335

@byquanton

Description

@byquanton

The GSON Serializer uses the deprecated ClickEvent.custom(Key Key, String data) method and causes a IllegalStateException (Expected STRING but was BEGIN_OBJECT at path $.click_event.payload) when trying to parse a ClickEvent with a custom callback that uses NBT for the payload.

Example Code

try (InputStream stream = Main.class.getResourceAsStream("/example.json")) {
    BufferedReader streamReader = new BufferedReader(new InputStreamReader(stream));
    JsonElement jsonElement = new JsonParser().parse(streamReader);

    GsonComponentSerializer serializer = GsonComponentSerializer.builder()
            .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get())
            .build();

    Component component = serializer.deserializeFromTree(jsonElement);
}
{
  "extra": [
    {
      "click_event": {
        "id": "paper:click_callback",
        "payload": {
          "id": [
            1034630811,
            -1696642542,
            -1523289780,
            -1589453925
          ]
        },
        "action": "custom"
      },
      "text": "Some Text"
    }
  ],
  "text": ""
}

Similar Issue for Serializer not accepting a null payload: #1326
Related: GeyserMC/Geyser#5932

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions