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
When deserializing JSON that does not fit the target classes, SerializationException should be thrown always. If the input JSON has the wrong type (e.g. 123 where a Boolean is expected), IllegalStateException is thrown instead (by StreamingJsonDecoder, which uses toBooleanStrict, for example).
This makes it difficult to distinguish invalid JSON from other errors, especially in a server environment, where you want to inform clients that their request is invalid (as opposed to some internal server error).
To Reproduce
@Serializable
data classSerializerBug(valbooleanValue:Boolean)
funmain() {
val json =Json { }
// throws java.lang.IllegalStateException: 123 does not represent a Boolean
json.decodeFromString(SerializerBug.serializer(), """{"booleanValue": 123}""")
}
Expected behavior kotlinx.serialization.SerializationException is thrown instead of generic IllegalStateException.
Environment
Kotlin version: 1.4.21
Library version: 1.0.1
Kotlin platforms: Tested on JVM, but this bug exists in common code
Gradle version: 6.7
The text was updated successfully, but these errors were encountered:
When deserializing JSON that does not fit the target classes,
SerializationException
should be thrown always. If the input JSON has the wrong type (e.g.123
where aBoolean
is expected),IllegalStateException
is thrown instead (byStreamingJsonDecoder
, which usestoBooleanStrict
, for example).This makes it difficult to distinguish invalid JSON from other errors, especially in a server environment, where you want to inform clients that their request is invalid (as opposed to some internal server error).
To Reproduce
Expected behavior
kotlinx.serialization.SerializationException
is thrown instead of genericIllegalStateException
.Environment
The text was updated successfully, but these errors were encountered: