Sheroz Nazhmudinov
12/03/2020, 4:33 PMget
request, but i’m hitting MissingFieldException
when trying out post
.
Can smbd please check what I might be doing wrong? Thanks in advance! Some code snippets:
@Serializable
data class RegistrationParams(
val name: String,
val job: String
)
@Serializable
data class RegistrationResponse(
@SerialName("name") val name: String,
@SerialName("job") val job: String,
@SerialName("id") val id: String,
@SerialName("createdAt") val createdAt: String
)
val httpClient = HttpClient(Android) {
install(JsonFeature) {
val json = Json { ignoreUnknownKeys = true }
serializer = KotlinxSerializer(json = json)
}
}
suspend fun samplePostRequest(): RegistrationResponse = <http://client.post|client.post>(
urlString = "<https://reqres.in/api/users>",
) {
body = Json.encodeToString(
RegistrationParams.serializer(),
RegistrationParams(
name = "Neo",
job = "The Chosen One"
)
)
}
The error message says: Field 'name' is required, but it was missing
Joost Klitsie
12/03/2020, 5:05 PMbody = RegistrationParams(name = "Neo", job = "The Chosen One")
Joost Klitsie
12/03/2020, 5:05 PMJoost Klitsie
12/03/2020, 5:06 PMcontentType(ContentType.Application.Json)
Sheroz Nazhmudinov
12/03/2020, 5:10 PM