I am trying to serialize an item for storage in a JSON file that I’ve created. However, I’m not sure how to do this (or how to deserialize the it either)
There are a ton of different methods within the item stack and I’m not sure what i’m supposed to use.
Can someone point me in the right direction, so that I can figure this out?
I tried to reverse engineer it to deserialize the item stack from the string that provides, however i think i may be doing it wrong, am I misunderstanding the process here?
There are a couple different reasons. Primarily my familiarity with the JSON library that i’m using, but in general I prefer to work at a much lower level, as it allows me a lot more flexibility (of course, at the risk of having code break, or having issues such as this) in what I am able to do, and as an added bonus, I feel like it helps me learn a lot more about what it is that I’m doing than if I weren’t tinkering around. (which is another reason, i like to mess around with the code and see what i can break )
By the way, it seems as though I’m having some issues with this deserialization. It looks like configurate is complaining that it is unable to build the ItemStack, however it looks like its pointing to an issue with the DataSerializableTypeSerializer.deserialize() method on line 60, however the source code doesn’t even go that high of a line. I think i may need to update to the newer version of Sponge, i just remembered there was a new version out recently…
Fair enough. Yeah there was an issue with deserializing DataSerializables that I literally fixed yesterday, update to the latest snapshot of SpongeForge or SpongeVanilla and you should be fine.
The test that I am performing takes the players held item stack, serializes it (which works perfectly fine), and then to test, immediately passes the JSONObject back into the deserializer. (this is where it fails, and points towards the node.getValue() method)
The toString() method of the JSON library is basically the serialization method, it creates the text version of a JSON object. Its worth noting that keeping it in string form and passing the string back also produced this error.
node.getNode("item") and just node.setValue(TypeToken.of(ItemStack.class), item) directly. You’re trying to deserialize the ItemStack from a different node than you are serializing it to.