https://kotlinlang.org logo
Title
c

Charles Maina

03/17/2023, 11:42 AM
Hi all .. I have been getting this 404 error response when trying to return a serialized data class using kotlin serialization.
"Skipping response body transformation from HttpStatusCode to OutgoingContent for the POST /register request because the HttpStatusCode type is ignored. See [ContentNegotiationConfig::ignoreType]". Anyone knows how I can go about it? I have tried searching online first.
This is how I am installing content negotiation.
fun Application.configureSerialization() {
    install(ContentNegotiation) {
        json()
    }
}
a

Aleksei Tirman [JB]

03/17/2023, 12:40 PM
Can you share the code for responding with a data class?
c

Charles Maina

03/17/2023, 12:50 PM
This is the route for registering a user
post("/register") {
    val userFromClient = call.receive<User>()
    authenticationBusiness.registerUser(user = userFromClient).collect { registrationResult ->
        when (registrationResult) {
            is OperationResult.Success -> {
                call.respond(status = HttpStatusCode.Created, message =registrationResult.data)
            }

            is OperationResult.Failure -> {
                call.respond(status = HttpStatusCode.Conflict, message = "Unable to register user")
            }
        }
    }
}
registrationResult.data results in an AccessModel class as shown here
@Serializable
data class AccessModel(
    val accessToken: String,
    val refreshToken: String,
    val expiresIn: String
)
This one here is the User model
@Serializable
data class User(
    val id: Int,
    val streetName: String,
    val password: String,
    val phoneNumber: String,
    val isPlayer: Boolean
)
a

Aleksei Tirman [JB]

03/17/2023, 2:12 PM
So a
/register
POST request results in the 404 status code?
If so can you check via a debugger what value the
registrationResult
variable contains?
c

Charles Maina

03/17/2023, 6:16 PM
@Aleksei Tirman [JB] Yeah . The
/register
POST request does result in the 404 error.
a

Aleksei Tirman [JB]

03/20/2023, 9:45 AM
Can you check that the handler for the route is actually executed?