Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no data holder converter registered to convert from a class net.kyori.adventure.nbt.api.BinaryTagHolderImpl instance to a interface net.kyori.adventure.text.serializer.gson.GsonDataComponentValue (on field minecraft:lore) #1130

Open
that-apex opened this issue Nov 18, 2024 · 0 comments

Comments

@that-apex
Copy link

that-apex commented Nov 18, 2024

GsonComponentSerializer will fail to serialize an ItemStack that has components if it was previously deserialized with minimessage.

val item = ItemStack(Material.DIAMOND)
item.editMeta { it.lore(listOf(Component.text("my lore"))) }
val baseComponent = Component.translatable(item).hoverEvent(item.asHoverEvent())

val json1 = GsonComponentSerializer.gson().serialize(baseComponent) // fine
println(json1)

try {
    val reserialized = MiniMessage.miniMessage().deserialize(MiniMessage.miniMessage().serialize(baseComponent))
    GsonComponentSerializer.gson().serialize(reserialized)
} catch (e: Exception) {
    e.printStackTrace()
}

results in

{"hoverEvent":{"action":"show_item","contents":{"id":"minecraft:diamond","count":1,"components":{"minecraft:lore":["\"my lore\""]}}},"translate":"item.minecraft.diamond"}
java.lang.IllegalArgumentException: There is no data holder converter registered to convert from a class net.kyori.adventure.nbt.api.BinaryTagHolderImpl instance to a interface net.kyori.adventure.text.serializer.gson.GsonDataComponentValue (on field minecraft:lore)
	at net.kyori.adventure.text.event.DataComponentValueConverterRegistry.convert(DataComponentValueConverterRegistry.java:90)
	at net.kyori.adventure.text.event.HoverEvent$ShowItem.dataComponentsAs(HoverEvent.java:623)
	at net.kyori.adventure.text.serializer.gson.ShowItemSerializer.write(ShowItemSerializer.java:139)
	at net.kyori.adventure.text.serializer.gson.ShowItemSerializer.write(ShowItemSerializer.java:49)
	at com.google.gson.TypeAdapter$1.write(TypeAdapter.java:196)
	at com.google.gson.Gson.toJson(Gson.java:842)
	at net.kyori.adventure.text.serializer.gson.StyleSerializer.write(StyleSerializer.java:296)
	at net.kyori.adventure.text.serializer.gson.StyleSerializer.write(StyleSerializer.java:62)
	at com.google.gson.TypeAdapter$1.write(TypeAdapter.java:196)
	at com.google.gson.Gson.toJson(Gson.java:842)
	at com.google.gson.Gson.toJsonTree(Gson.java:712)
	at net.kyori.adventure.text.serializer.gson.ComponentSerializerImpl.write(ComponentSerializerImpl.java:252)
	at net.kyori.adventure.text.serializer.gson.ComponentSerializerImpl.write(ComponentSerializerImpl.java:77)
	at com.google.gson.TypeAdapter$1.write(TypeAdapter.java:196)
	at com.google.gson.Gson.toJson(Gson.java:842)
	at com.google.gson.Gson.toJson(Gson.java:812)
	at com.google.gson.Gson.toJson(Gson.java:759)
	at com.google.gson.Gson.toJson(Gson.java:736)
	at net.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.serialize(GsonComponentSerializerImpl.java:104)
	at net.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.serialize(GsonComponentSerializerImpl.java:41)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant