Skip to content
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][JAVA] java.util.Scanner used in ApiClient.java does not have character encoding set and thus uses JVM default encoding #16818

Closed
5 of 6 tasks
wojciechkl opened this issue Oct 13, 2023 · 4 comments · Fixed by #17998

Comments

@wojciechkl
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Scanner used for response stream reading uses JVM default encoding (does not have second parameter "charsetName" provided - https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#Scanner-java.nio.file.Path-java.lang.String-).

java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");

In my case this makes generated code unusable because API provider (who controls yaml with spec) uses diaciritics in some params. And those params are changed by OpenApi into enums. And when data, with those params, is actually returned from REST end point the encoding does not match and I get java.lang.IllegalArgumentException Exception - Unexpected value '...' in fromValue method.

openapi-generator version

7.0.1

Suggest a fix

I can provide a patch here, but first I would like to discuss which should be preffered way of solving this - forcing "UTF-8" encoding (which works for me) or providing new parameter that would allow to choose encoding.

@youngInnovator
Copy link

I will suggest to use parameter and if parameter is null use default as UTF-8

@wing328
Copy link
Member

wing328 commented Nov 5, 2023

or providing new parameter that would allow to choose encoding.

What about adding a property in ApiClient.java (default to current behaviour) to let users choose?

@AB-xdev
Copy link
Contributor

AB-xdev commented Feb 29, 2024

I think a way easier fix would be to use EntityUtils#toString as it automatically derives the charset from the content type.

@AB-xdev
Copy link
Contributor

AB-xdev commented Feb 29, 2024

I quickly created a PR that should fix this: #17998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants