简体   繁体   English

使用 Jackson 库的 Bukkit ItemStack 序列化

[英]Bukkit ItemStack serialization using Jackson library

I'm trying to serialize and deserialize an ItemStack using the Jackson JSON library.我正在尝试使用 Jackson JSON 库对 ItemStack 进行序列化和反序列化。 So far I have managed to serialize the ItemStack however when I go to deserialize it, I get the following error:到目前为止,我已经设法序列化 ItemStack 但是当我 go 反序列化它时,我收到以下错误:

com.fasterxml.jackson.databind.JsonMappingException: Can not find a (Map) Key deserializer for type [simple type, class org.bukkit.enchantments.Enchantment]

I'm not sure why this is.我不确定这是为什么。 I have tried different versions of the Jackson library to no avail, I still get the exact same error.我尝试了不同版本的 Jackson 库无济于事,我仍然得到完全相同的错误。 I have tried serializing ItemStacks with and without enchantments and I still get it.我尝试过序列化带有和不带有附魔的 ItemStacks,但我仍然得到它。 Any help would be appreciated here.任何帮助将不胜感激。

I am using the below code to deserialize my ItemStack:我正在使用下面的代码来反序列化我的 ItemStack:

try {
    ItemStack item = objectMapper.readValue(gang.getVaultItems().get(slot), ItemStack.class);
} catch (IOException ex) {
    ex.printStackTrace();
}

You're going to likely have to use custom deserialization for this.您可能必须为此使用自定义反序列化。 You can read more about it here .你可以在这里阅读更多关于它的信息。 It is worth noting that by default Bukkit uses a fairly custom YAML implementation to handle serialization and deserialization.值得注意的是,Bukkit 默认使用相当定制的 YAML 实现来处理序列化和反序列化。 Look into ConfigurationSerializable if you're not familiar.如果您不熟悉,请查看ConfigurationSerializable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM