That is where the serializer is actually being use...
# getting-started
c
That is where the serializer is actually being used
🧵 3
nvm got it
Copy code
object ItemEnchantSerializer : KSerializer<ItemEnchant> {
    override val descriptor: SerialDescriptor = ItemEnchant.serializer().descriptor

    override fun serialize(encoder: Encoder, value: ItemEnchant) {
        println("serialize $value");
        val enchantment = Enchantment.getByKey(NamespacedKey.minecraft(value.id.toString().lowercase())) ?: return
        val itemEnchant = ItemEnchant(enchantment, value.level)
        encoder.encodeSerializableValue(ItemEnchant.serializer(), itemEnchant)
    }

    override fun deserialize(decoder: Decoder): ItemEnchant {
        println(decoder.decodeString())
        return decoder.decodeSerializableValue(ItemEnchantSerializer)
    }
}
Copy code
@Serializable
@SerialName("ItemEnchant")
data class ItemEnchant(@Contextual val id: Enchantment, val level: Int)
Copy code
@Serializable
data class LemonItemData(val id: String,
                         val name: String,
                         @EncodeDefault val lore: List<String> = listOf(),
                         @Serializable(with = MaterialSerializer::class) val material: Material,
                         @EncodeDefault @Serializable(with = ItemEnchantSerializer::class) val enchants: ArrayList<ItemEnchant> = arrayListOf(),
                         @EncodeDefault val unbreakable: Boolean = false
                    )
t
Kotlin Bukkit dev here, feel free to reach out over DM. Won’t always be fast but I can eventually respond.
c
Alright
t
Still having the issue?
c
Yeah
I'm sure there is an easy fix for this, but I just started w/ Kotlin
t
You’re using an ArrayList, maybe the serializer you are using expect an Array
c
I'll send the error in DMs
r
It always saddens me when people solve things in private. 😞 https://xkcd.com/979/
t
I’ll make sure the solve makes it’s way here 🙂
🙇 1
s
this picture is missing the "fixed :>" message the thread creator posted like half a year later
👍 1
t
The issue is the
println(decoder.decodeString())
in deserialize.
It’s decoding a string before the array or object structures are started
I don’t think
@Serializable(with = ItemEnchantSerializer::class)
is necessary either
Copy code
@Serializable
@SerialName("ItemEnchant")
data class ItemEnchant(@Contextual @Serializable(with = ItemEnchantSerializer::class) id: Enchantment, val level: Int)
It probably needs to move to here
c
Fixed it!
One quick thing
When decoding the json, the & gets turned into an ?
Maybe it's the println encoding
Once it goes trough the decodeFromString it turns into ?
nvm got it