-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Post request body serialization doesn't work #202
Comments
Don't use ktorfit due to Foso/Ktorfit#202
I'm facing the same issue. |
Thank you for the bug report |
I fixed it, i'm planning to release a new version on the weekend |
Do you expect to have a new release soon ? |
I found that if you set the body as a string, it would work, but with data classes, it fails, maybe the inferred type is being lost for some reason?! |
Have you tried it with 1.0.1 ? |
Just tried with v1.0.1 and I can see that the issue is now fixed. |
ktorfit = "2.2.0" @POST("api/v1/statuses")
suspend fun createPost(
@Body createPostDto: CreatePostDto
): Call<PostDto>
@Serializable
data class CreatePostDto(...) I receive an error
The content negotiation plugin is installed: HttpClient {
install(ContentNegotiation) { json(json) }
} |
It works only if I convert the body object to JSON and add a content-type header @Headers("Content-Type: application/json")
@POST("api/v1/statuses")
suspend fun createPost(
@Body createPostDto: String
): Call<PostDto> A similar problem is here: https://stackoverflow.com/questions/75672624/is-it-possible-to-use-a-serializable-data-class-as-post-request-body-in-ktorfit |
Ktorfit version
1.0.0
What happened and how can we reproduce this issue?
Sample repo
https://github.com/alapshin/multiplayground/tree/aa09943fb7cf180ac57a28e8c9db95874da9f0b6
See
LoginComponent
class.There are two implementation of
LoginService
interface. One generated by Ktorfit (enabled by default) and one written by hand using Ktor directly (commented out).When sample app is launched and
Login
button is pressed login request is sent usingLoginService
.When LoginService implementation generated by Ktorfit is used post request body serialization fails with following stacktrace
But if I switch implementation to one wirtten by hand then request post body is serialized correctly.
HttpClient configuration is identical in both cases (see
NetworkComponent
). It seems that for some reasons Ktorfit doesn't set correctbodyType
onHttpRequest
but I can't figure why it happens.What did you expect to happen?
I expect implementation generated by Ktorfit serialize post body correctly.
Is there anything else we need to know about?
No response
The text was updated successfully, but these errors were encountered: