'french accents giving "<?>" in http responses with correct charset (Java)

Calling an API that returns french sentences, all the accented characters are displayed like <?> in my java code, even if the charset is well defined (application/json;charset=iso-8859-1).

Using postman or my web browser, I don't face any problem. I also tried to call the API with a Content-Type header with the value application/json;charset=UTF-8 or application/json;charset=iso-8859-1 but the problem remains the same. Any idea ?

response.getBody() gives:

{"sentences":[{"fr_value":"il �tait loin","dz_value":"kaan b3id","additional_information":{"personal_prounoun":"HE","verb":"�tre","adjective":"loin","tense":"pass�"}}],"count":1}

new String(response.getBody().getBytes(StandardCharsets.UTF_8)) gives exactly the same.

enter image description here

I'm using scribejava.

Edit: even saving the response in a file and opening it with NotePad++, the result is similar: enter image description here



Solution 1:[1]

Problem solved using the following code :

      httpResponse.setContentType("application/json;charset=UTF-8");
      mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);

Solution 2:[2]

You need to read it as ISO-8859-1. Not sure what then as I don't know what you're doing. My https://technojeeves.com/index.php/aliasjava1/51-transcode-in-java is helpful. With wget: wget -O - us-central1-dz-dialect-api.cl… | xcode -ie Latin1 (I made 'xcode' to invoke that Java app)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Redouane B.
Solution 2 g00se