Still have some error I get after migrating to ver...
# ktor
t
Still have some error I get after migrating to version 2.0.0-beta-1 that I do not understand (Ktor-Client). If I try to execute the following code:
Copy code
override suspend fun authenticateUser(userNameHash: String, passwordHash: String): UserAuthData? {
        return try {
            <http://client.post|client.post>(HttpRoutes.AUTHENTICATE_USER_FQDN) {
                contentType(ContentType.Application.Json)
                setBody {
                    UserRegistrationData(
                        userNameHash = userNameHash,
                        passwordHash = passwordHash
                    )
                }
            }.body<UserAuthData>()
        } catch (e: Exception) {
 ...
           }
    }
Data Class looks like this:
Copy code
@kotlinx.serialization.Serializable
data class UserRegistrationData(
    val userNameHash: String,
    val passwordHash: String
)
HttpClient
Copy code
HttpClient(Android) {
....
        install(ContentNegotiation) {
                json(Json {
                    ignoreUnknownKeys = true
                    isLenient = true
                }
                )
            }
....
}
Dependencies (for serialization)
Copy code
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
Error Message: Line: 58, Method: authenticateUser: Serializer for class 'null' is not found. Mark the class as @Serializable or provide the serializer explicitly.
s
Is
setBody
supposed to be taking a lambda argument?
I would have expected
Copy code
setBody(UserRegistrationData(
    userNameHash = userNameHash,
    passwordHash = passwordHash
))
Probably it's trying to serialize the lambda function, hence the error
t
Thanks Sam! That solved my issue! I appreciate your time and help!! 👌😀
blob smile 1