silk icon indicating copy to clipboard operation
silk copied to clipboard

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

Open hellozyemlya opened this issue 5 months ago • 1 comments

See this structure:

@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)

hellozyemlya avatar Sep 05 '24 19:09 hellozyemlya