Skip to content

Commit

Permalink
Clarify example for SerializationException (#2806)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandwwraith authored Sep 18, 2024
1 parent 2f1dbdb commit 21311a6
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import kotlinx.serialization.descriptors.*
* It is also an established pattern to validate input in user's classes in the following manner:
* ```
* @Serializable
* class Foo(...) {
* class User(val age: Int, val name: String) {
* init {
* required(age > 0) { ... }
* require(age > 0) { ... }
* require(name.isNotBlank()) { ... }
* }
* }
*
* Json.decodeFromString<User>("""{"age": -100, "name": ""}""") // throws IllegalArgumentException from require()
* ```
* While clearly being serialization error (when compromised data was deserialized),
* Kotlin way is to throw `IllegalArgumentException` here instead of using library-specific `SerializationException`.
Expand Down

0 comments on commit 21311a6

Please sign in to comment.