Serialisation and de-serialisation of book meta results in different item NBT than original

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      When de-serialising a serialised written (signed) book meta it will result in a different meta than it originally was. When applied to an item stack it will create two different items. (E.g. when saving into and getting from a config)

      The difference between the two items will be in the pages section of the NBT data. The item that went through the serialisation process will have the book text in an extra tag and not in the text tag like the Vanilla one. (See NBTExplorer screenshot)

      This does not happen with unsigned books.

      I included a plugin with which one can test this, just get and sign a book with text and run the command /metatest while holding the book.

       

      Here is the code I use in the plugin for completion sake, it has to use a CraftClass as ConfigurationSerializable does not define a deserialize method in Bukkit:

      Map<String, Object> serialized = item.getItemMeta().serialize();
      try {
          ItemMeta deserialised = CraftMetaBook.SerializableMeta.deserialize(serialized);
          ItemStack clone = new ItemStack(item);
          clone.setItemMeta(deserialised);
          if (item.isSimilar(clone)) {
              sender.sendMessage("Item is the same after serialisation and deserialisation!");
          } else {
              sender.sendMessage("Item is NOT the same after serialisation and deserialisation! Giving you the item...");
              ((Player) sender).getInventory().addItem(clone);
          }
      } catch (Throwable throwable) {
          sender.sendMessage("Error while deserialising: " + throwable.getMessage());
          throwable.printStackTrace();
      }
      

        1. NBTExplorer_2017-04-27_17-07-17.png
          15 kB
          Phoenix616

          [SPIGOT-3206] Serialisation and de-serialisation of book meta results in different item NBT than original

          Anton added a comment -

          Why is it not possible to fix it? Those are really a big problem if we talk about using signed books as part of the gameplay.

          Anton added a comment - Why is it not possible to fix it? Those are really a big problem if we talk about using signed books as part of the gameplay.

          blablubbabc added a comment -

          Wouldn't it be possible to save the pages in their stringified chat component format ("{text: "..", color: "..", ..}") and parse them from that, which should ideally be lossless? The deserialization would also need to be able to parse from the legacy format (for example by using the item's serialized data version to determine whether its using the old or new format).

          blablubbabc added a comment - Wouldn't it be possible to save the pages in their stringified chat component format ("{text: "..", color: "..", ..}") and parse them from that, which should ideally be lossless? The deserialization would also need to be able to parse from the legacy format (for example by using the item's serialized data version to determine whether its using the old or new format).

          md_5 added a comment -

          Unavoidable with the conversion from section signs and backwards

          md_5 added a comment - Unavoidable with the conversion from section signs and backwards

            Assignee:
            Unassigned
            Reporter:
            Phoenix616
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: