define request content type as application/json for default body param#12
Draft
fullkomnun wants to merge 1 commit intocromefire:multiplatform-clientfrom
Conversation
Owner
|
I think you can set the content type from open api, I'm currently not aware whethere there's a template check thingy with which we can check that but we should probably only default to json (I think that's also how swagger ui handles that for example), so we don't accidentally override anything. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, for requests with a (non Formdata) body param, body is being set to a given argument value but
ContentTypeis not defined so when providing an object that can be serialised to Json as value - it throw the following errorjava.lang.IllegalStateException: Fail to serialize body. Content has type: class ******** (Kotlin reflection is not available), but OutgoingContent expected. If you expect serialized body, please check that you have installed the corresponding feature(like 'Json') and set 'Content-Type' header.According to Ktor docs: "If you install the JsonFeature, and set the content type to application/json you can use arbitrary instances as the body, and they will be serialised as JSON".
So we might want to set
contentType(ContentType.Application.Json)in that case (might want to do that only if the body param type is not a String nor a subtype of OutgoingContent).Otherwise, the only option for consumer to avoid that error is to set a default ContentType for HttpClient requests:
defaultRequest { contentType(ContentType.Application.Json) }