0

I am writing an automation tool, that mostly send requests and get JSON responses from a server. When I run my code directly from IntelliJ - I get a proper response. But, when I run my program from the console there is a problem. Special Spanish or French chars are being displayed in a wrong way.

For example:

We’ve 

My code:

 RestResponse restResponse = restRequest.sendRequest();
 JSONObject jsonResponse = restResponse.getResponseJson();

What may be the cause for this error and how to get the foreign language chars to appear as they should?

SylwekFr
  • 308
  • 3
  • 21
Tal Angel
  • 1,301
  • 3
  • 29
  • 63

1 Answers1

1

The error might be cause by the character encoding, in IntelliJ you probably have already defined character encoding but not in the console.
So you can define the console encoding to UTF8 :
Console.OutputEncoding = Encoding.UTF8;
You can find some hint there :
- How to get a UTF-8 JSON
- Encode String to UTF-8
- System.out character encoding

SylwekFr
  • 308
  • 3
  • 21
  • I tried using your code with import java.io.Console, but is doesn't compile. How to effects the Console via Java code? – Tal Angel Feb 24 '20 at 13:38
  • I suppose java -Dfile.encoding but I am really not an expert in Java so it's only a supposition – SylwekFr Feb 25 '20 at 11:37