-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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] content-type application/json using iso-8859-1 instead of utf-8 (accent and special char not supported) #12797
Comments
fixed |
i think you should use [ content-Type: application/json;charset=UTF8 ] to specify charset , instead of modify method: getContentType. #13058 want support custom contentType, it will modify it back |
This is a also a possibility but using application/json with ISO-8859-1 it is not compliant with RFC4627 and can lead to unwanted behavior in Java HTTP call such as unexpected character replacement. |
Issue re-opened as changes has been revert. The behavior is no more RFC4627 compliant |
I would also like the default behavior to comply with the RFC4627 section 3, that states:
RFC5627 section 1.1 states the term SHALL is to be interpreted as described in RFC2119. As per RFC2119 section 1,
Furthermore, RFC4627 section 1 states that:
I can't see any reason for the encoding to be ISO-8859-1 when the content of the JSON strings are unicode characters. Having to specify the charset to UTF-8 on each and every operation in the OpenAPI specification, as I see it:
|
Any news on this topic ? UTF-8 default encoding for application/json seems a good idea :) |
Hey, I also just stumbled over this and we'll have to modify quite a few API-specs due to this, which is bizarre, given UTF-8 should be the default. I suppose this is especially problematic outside of English speaking countries. Would greatly appreciate a fix =) |
I stumbled upon this issue, is it possible to solve this in upcoming release ? |
I also just ran into this issue. A fix would be greatly appreciated. |
…tion as ISO-8859-1 is used by default in apache-httpclient (OpenAPITools/openapi-generator#12797)
…tion as ISO-8859-1 is used by default in apache-httpclient (OpenAPITools/openapi-generator#12797)
I propose to force a content-type with UTF-8 encoding when serializing the json:
|
I'd like to have a fix for this as well. For now, we're working around it by providing a subclassed |
This commit fixes an issue with the codegeneration - when specifying a charset in a JSON content type, the resulting request / response bodies are missing the JSON serializer. The charset is usually redundant, since JSON should usually be encoded using UTF-8 (see https://www.rfc-editor.org/rfc/rfc8259#section-8.1), however there are some code generators out there that do not honor this (for example: OpenAPITools/openapi-generator#12797)
fixes following related issue: OpenAPITools#12797
* fix(java): apache-httpclient serialization error fixes following related issue: #12797 * docs(java): update samples and docs
Description
Using the plugin org.openapitools:openapi-generator-maven-plugin:6.0.1 to generator a Java client from an openapi3.yml spec file, I have noticed requestBody content-type application/json generate a Java Api that does not support accent or special characters.
For example
)çàç!è!§è(‘“é‘(§‘“é&“’(§è!çà
send to the Java API is transformed to)???!?!??(????(????&??(??!
in the HTTP call (wireshark inspection).Problem : request content-type application/json is parsed as application/json with no charset. Therfore, using apache-httpclient, the generator use org.apache.httpcomponents:httpcore where the default charset iso-8859-1 which does not support accent.
application/json with ISO-8859-1 it is not compliant with RFC4627. In my case it lead to unwanted behavior in Java HTTP call such as unexpected character replacement.
openapi-generator version
org.openapitools:openapi-generator-maven-plugin:6.0.1
library : apache-httpclient
OpenAPI declaration file content or url
Generation Details
pom.xml
Steps to reproduce
Generator the Java client using the OpenApi plugin generator.
Then use the ApiClient TestBody api to send special character such as
)çàç!è!§è(‘“é‘(§‘“é&“’(§è!çà
Using wireshark or another tool inspect the payload request content.
=> Special caracters has been replaces by interrogation point.
Related issues/PRs
Not found
Suggest a fix
Use UTF-8 charset proposed by apache httpcore such as here in httpcore.
Inside generated ApiClient.java, the getContentType method is :
And can be replaced by the following to retrieve an utf8 charset inside the content-type :
The text was updated successfully, but these errors were encountered: