-
Notifications
You must be signed in to change notification settings - Fork 2
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
[BUG] Config option ignoreUnknownKeys
breaks when there are unknown keys at the end
#8
Comments
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: |
Just tried, works with 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
The text was updated successfully, but these errors were encountered: