Closed RaphaelTarita closed 2 years ago
Thanks for reporting this! I'll take a look at what's going on...
Reproduction:
import kotlinx.serialization.*
import net.benwoodworth.knbt.*
@NbtRoot(name = "")
@Serializable
data class LevelRoot(
@SerialName("Data")
val data: LevelData
)
@SerialName("Data")
@Serializable
data class LevelData(
@SerialName("LevelName")
val levelName: String
)
fun main() {
val nbt = Nbt {
variant = NbtVariant.Java
compression = NbtCompression.Gzip
ignoreUnknownKeys = true
}
val levelTag = buildNbtCompound("") {
putNbtCompound("Data") {
put("LevelName", "test")
putNbtList<Nothing>("ScheduledEvents") {}
}
}
nbt.decodeFromNbtTag<LevelRoot>(levelTag) // error
}
Could you give 0.9.2-SNAPSHOT a try?
You'll need to add the maven snapshot repo:
https://s01.oss.sonatype.org/content/repositories/snapshots/
Just tried, works with 0.9.2-SNAPSHOT
What I tried (and therefore validated):
parsing multiple different level.dat
files using the above mentioned model classes, then extracting [root]/Data/LevelName
.
Thanks!
Awesome!! 0.9.2 should be published soon with the fix :)
I was trying to parse
level.dat
to get the level name, but it turns out that it doesn't work with the modelsand the config
The following exception + stacktrace is thrown:
I found out that this exception is thrown when
ignoreUnknownKeys
istrue
I started with testing this with
level.dat
, trying to access[root]/Data/LevelName
. That didn't work because there are other keys afterLevelName
that are not present in the model. Then I tested it with a constructed nbt file that basically just containedThis could be deserialized into the models. Then, I added a random key that is not present in the models:
This still works, since
ignoreUnknownKeys
is turned on. However, when I swap the positions ofScheduledEvents
andLevelName
:The above error is thrown.
Kotlin 1.5.30 KXS 1.2.2 knbt 0.9.1