File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
core/commonMain/src/kotlinx/serialization Expand file tree Collapse file tree 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.*
2222 * It is also an established pattern to validate input in user's classes in the following manner:
2323 * ```
2424 * @Serializable
25- * class Foo(... ) {
25+ * class User(val age: Int, val name: String ) {
2626 * init {
27- * required (age > 0) { ... }
27+ * require (age > 0) { ... }
2828 * require(name.isNotBlank()) { ... }
2929 * }
3030 * }
31+ *
32+ * Json.decodeFromString<User>("""{"age": -100, "name": ""}""") // throws IllegalArgumentException from require()
3133 * ```
3234 * While clearly being serialization error (when compromised data was deserialized),
3335 * 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