You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Serializable serializers are successfully decoding JSON that is missing commas between its properties
To Reproduce
These tests will pass with multiple properties and multiple combinations of missing commas, so not a special case of N = 2.
importkotlinx.serialization.Serializableimportkotlinx.serialization.SerializationExceptionimportkotlinx.serialization.json.Jsonimportkotlinx.serialization.json.JsonObjectimportorg.junit.jupiter.api.Testimportstrikt.api.expectThatimportstrikt.api.expectThrowsimportstrikt.assertions.containsimportstrikt.assertions.isEqualToimportstrikt.assertions.isNotNullclassJsonTest {
@Serializable
data classFoo(
valbar:String,
valbaz:Int,
)
val invalidEncoding ="""{ "bar": "buz" "baz": 1 }""".trimIndent()
@Test
fun`decoding invalid JSON is tolerated by @Serializable serializers`() {
val result =Json.decodeFromString(Foo.serializer(), invalidEncoding)
expectThat(result) {
get(Foo::bar) isEqualTo "buz"
get(Foo::baz) isEqualTo 1
}
}
@Test
fun`decoding invalid JSON is not tolerated by JsonObject's serializer`() {
expectThrows<SerializationException> {
Json.decodeFromString(JsonObject.serializer(), invalidEncoding)
}.and {
get(SerializationException::message).isNotNull().contains("Unexpected JSON token")
}
}
}
Expected behavior
The decoding invalid JSON is tolerated by @Serializable serializers test should fail decoding the invalid JSON
Environment
Kotlin version: 1.8.20
Library version: 1.4.1
Kotlin platforms: JVM
Gradle version: 7.5
IDE version (if bug is related to the IDE) IntelliJ 2023.1 CE
Other relevant context JDK 17
The text was updated successfully, but these errors were encountered:
gmkohler
changed the title
decodeFromString with data class serializers tolerates missing commas in JSON
Json.decodeFromString with data class serializers tolerates missing commas in encoded data
Apr 28, 2023
Describe the bug
@Serializable
serializers are successfully decoding JSON that is missing commas between its propertiesTo Reproduce
These tests will pass with multiple properties and multiple combinations of missing commas, so not a special case of N = 2.
Expected behavior
The
decoding invalid JSON is tolerated by @Serializable serializers
test should fail decoding the invalid JSONEnvironment
The text was updated successfully, but these errors were encountered: