okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

incorrect JSON media type in example

Open reschke opened this issue 3 years ago • 3 comments

https://github.com/square/okhttp#post-to-a-server says:

public static final MediaType JSON
    = MediaType.get("application/json; charset=utf-8");

But application/json does not define a charset parameter.

reschke avatar Sep 08 '22 10:09 reschke

It's not clear it's an error rather than just redundant

https://www.iana.org/assignments/media-types/application/json

Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.

Same in https://www.rfc-editor.org/rfc/rfc8259

To make this change, it would have to be in the docs but also the code, since we resolve the charset

https://github.com/square/okhttp/blob/34d5cba5a889b8219d997fbb4153ddb4a5e51319/okhttp/src/jvmMain/kotlin/okhttp3/internal/internal.kt#L61

I suspect we don't want to implement all possible mime type conventions.

yschimke avatar Sep 09 '22 12:09 yschimke

Well, having that example is minimally misleading. It implies that you could have something other than UTF-8, and that would have an effect which in general is not true.

reschke avatar Sep 09 '22 13:09 reschke

Sure, if you want to submit a PR to fix the doc, then happy to simplify the example.

yschimke avatar Sep 09 '22 13:09 yschimke

Here is the PR with the fix, please review -> https://github.com/square/okhttp/pull/7494

mrajesh09 avatar Oct 28 '22 16:10 mrajesh09