-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that serialization exception is thrown from JSON parser on inv…
…alid inputs Fixes #704
- Loading branch information
Showing
9 changed files
with
96 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
runtime/commonTest/src/kotlinx/serialization/json/JsonParserFailureModesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.json | ||
|
||
import kotlinx.serialization.* | ||
import kotlin.test.* | ||
|
||
class JsonParserFailureModesTest : JsonTestBase() { | ||
|
||
@Serializable | ||
data class Holder( | ||
val id: Long | ||
) | ||
|
||
@Test | ||
fun testFailureModes() = parametrizedTest { | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id": "}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id": ""}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id":a}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id":2.0}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id2":2}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id"}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"id}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"i}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{"}""", it) } | ||
assertFailsWith<MissingFieldException> { Json.plain.parse(Holder.serializer(), """{}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """}""", it) } | ||
assertFailsWith<JsonDecodingException> { Json.plain.parse(Holder.serializer(), """{""", it) } | ||
} | ||
} |