ITADN

data class with null nullable field is failed to decode(probably wrongly encoded)

#63Openhellozyemlya 创建于 2024-09-05
H
hellozyemlyacommented
See this [structure](https://github.com/hellozyemlya/cool-resource-finder/blob/d8f8cfe522461aab2fb8451bfd09e89ef0677aa8/common/src/main/kotlin/hellozyemlya/resourcefinder/items/ResourceFinderCompass.kt#L32): ``` @Serializable data class CompassNbtV0( var compassId: Int = 0, var data: CompassData? = null, ) ``` when encoded, there is no "data" with empty list, or whatever. Exception is: ``` java.lang.ClassCastException: class net.minecraft.nbt.NbtCompound cannot be cast to class net.minecraft.nbt.NbtList (net.minecraft.nbt.NbtCompound and net.minecraft.nbt.NbtList are in unnamed module of loader net.fabricmc.loader.impl.launch.knot.KnotClassLoader @185d8b6) at net.silkmc.silk.nbt.serialization.decoder.NbtTagDecoder.decodeNotNullMark(Tag.kt:60) at kotlinx.serialization.internal.NullableSerializer.deserialize(NullableSerializer.kt:30) at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:257) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16) at net.silkmc.silk.nbt.serialization.decoder.NbtTagDecoder.decodeSerializableValue(Tag.kt:44) at net.silkmc.silk.nbt.serialization.Nbt.decodeFromNbtElement(NbtSerialization.kt:23) at hellozyemlya.resourcefinder.items.ResourceFinderCompass.getClientCompassData(ResourceFinderCompass.kt:205) at hellozyemlya.resourcefinder.ResourceFinderClient.renderPositionedArrows(ResourceFinderClient.kt:76) at hellozyemlya.resourcefinder.ResourceFinderClient.renderCompass(ResourceFinderClient.kt:204) ```
0 条评论