File tree 1 file changed +4
-2
lines changed
core/commonMain/src/kotlinx/serialization
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,14 @@ import kotlinx.serialization.descriptors.*
22
22
* It is also an established pattern to validate input in user's classes in the following manner:
23
23
* ```
24
24
* @Serializable
25
- * class Foo(... ) {
25
+ * class User(val age: Int, val name: String ) {
26
26
* init {
27
- * required (age > 0) { ... }
27
+ * require (age > 0) { ... }
28
28
* require(name.isNotBlank()) { ... }
29
29
* }
30
30
* }
31
+ *
32
+ * Json.decodeFromString<User>("""{"age": -100, "name": ""}""") // throws IllegalArgumentException from require()
31
33
* ```
32
34
* While clearly being serialization error (when compromised data was deserialized),
33
35
* Kotlin way is to throw `IllegalArgumentException` here instead of using library-specific `SerializationException`.
You can’t perform that action at this time.
0 commit comments