Deserialization of config node fails at data manipulators


My goal is to save any ItemStackSnapshot (with data or custom data) in a global way. I don’t like to attach the ItemStackSnapshot to a player or something else. It should be accessible globally. I decided to use a config file.

There are DataTranslators for translating a DataContainer to a ConfigurationNode. That works as intended.

Deserializing a ConfigurationNode back to a DataView also works(the data is present when debugging it).
The problem arises when I try to get the serialized ItemStackSnapshot out of the DataView.

Here is my little test code:

CommentedConfigurationNode rootNode = configLoader.load();

CommentedConfigurationNode node = rootNode.getNode("itemstack-snapshot");

ItemStackSnapshot itemStackSnapshot = ItemStack.builder()
            .add(Keys.BOOK_AUTHOR, Text.of("Author One"))

// To node
ConfigurationNode itemStackNode = DataTranslators.CONFIGURATION_NODE.translate(itemStackSnapshot.toContainer());

// From node
DataContainer dataContainer = DataTranslators.CONFIGURATION_NODE.translate(itemStackNode);
ItemStackSnapshot deserializedItemStackSnapshot = Sponge.getDataManager()
    .deserialize(ItemStackSnapshot.class, dataContainer).orElse(null);

// And see result in config file for easier debugging

The critical part is
ItemStackSnapshot deserializedItemStackSnapshot = Sponge.getDataManager() .deserialize(ItemStackSnapshot.class, dataContainer).orElse(null);

The deserializedItemStackSnapshot isn’t null, that’s not the problem. The problem is that the data(here the author) is not present anymore. It was present in the deserialized DataView.

Thanks in advance!

1 Like

Any idea?

May I ping @gabizou?

This is my working code: public static void doStuff(ConfigurationLoader<CommentedConfigurationNode> loade -