Hello have somebody any elegant solution vor validation I saw the following `feature` is still open...
m
Hello have somebody any elegant solution vor validation I saw the following
feature
is still open 🙂 https://github.com/Kotlin/kotlinx.serialization/issues/318 for https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/basic-serialization.md#data-validation
t
What about validation in
init
?
Copy code
init {
    require(email.length > 2)
}
👍 1
m
I struggle with propagation server to client
t
Do you want validation on server only?
👍 1
m
at the moment yes . try to replace jackson with it. in a springboot app
t
For start
Copy code
init {
    if (JAVA_MODE) {
        require(email.length > 2)
    }
}
d
Could also do with a small custom serializer.
n
we use konform.. we call validation logic before sending/and/or after receiving the Validator<T> is either in the companion object or a extension on it keeps all validation in one block of code but makes it possible to call from anywhere
m
I will check it out as well thx https://www.konform.io
what about https://github.com/valiktor/valiktor some experiences as well ?
I forget to anyway put it in something like https://datatracker.ietf.org/doc/html/rfc7807
🙈I was miss leading some part 🙂
n
interesting.. but that seems to just require the right
call.respondText(json.encodeToString(ProblemDetails.serializer(), problemDetails), ContentType("application", "problem+json"))
(ktor server example) or are you stuck on anything else ?
does not seems like the fields that the problem responds with are fixed anyways.. so you can make use of sealed classes and decode them with the same few lines as well