Hi all .. I have been getting this 404 error respo...
# ktor
c
Hi all .. I have been getting this 404 error response when trying to return a serialized data class using kotlin serialization.
Copy code
"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.
Copy code
fun Application.configureSerialization() {
    install(ContentNegotiation) {
        json()
    }
}
a
Can you share the code for responding with a data class?
c
This is the route for registering a user
Copy code
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
Copy code
@Serializable
data class AccessModel(
    val accessToken: String,
    val refreshToken: String,
    val expiresIn: String
)
This one here is the User model
Copy code
@Serializable
data class User(
    val id: Int,
    val streetName: String,
    val password: String,
    val phoneNumber: String,
    val isPlayer: Boolean
)
a
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
@Aleksei Tirman [JB] Yeah . The
/register
POST request does result in the 404 error.
a
Can you check that the handler for the route is actually executed?
a
Were you able to resolve this ? I have the same error
1001 Views