1

I have created a rest API using Spring boot. I am using JSON as the request and response type. Everything was working fine and I was happy until I tested it will some french words. I want my API to support all languages characters as this application might be used work wide. My JSON looks like below:

{
    "highlights": "Adiós",
    "language": "FR",
    "longDescription": "Adiós",
    "name": "Adiós",
    "shortDescription": "Adiós"
}

Spring is throwing the below error:

JSON parse error: Invalid UTF-8 middle byte 0x73; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x73\n at [Source: (PushbackInputStream); line: 2, column: 25]

I am using Java 11 with Spring boot 2.3.1.RELEASE

Edit:

I even tried sending Content-type as application/json; charset=utf-8 and adding same in @PostMapping consume and produce. But nothing helped.

Edit:

As suggested in the comment I also tried setting below spring property But still didn't work.

server.servlet.encoding.charset=UTF-8
server.servlet.encoding.force-response=true
Deepak Kumar
  • 1,246
  • 14
  • 38
  • Does this answer your question? [How to make spring boot default to application/json;charset=utf-8 instead of application/json;charset=iso-8859-1](https://stackoverflow.com/questions/55640629/how-to-make-spring-boot-default-to-application-jsoncharset-utf-8-instead-of-app) – Turing85 May 22 '21 at 11:28
  • It doesn't matter but it looks more like Spanish than French. Unlikely it causes the error, though. – Yuri Khristich May 22 '21 at 11:29
  • @Turing85 Thanks for comment but I have tried this also but still I am getting the same error msg – Deepak Kumar May 22 '21 at 11:30
  • @YuriKhristich I am not sure what language is this word, But I just want my API to support all the language. It does include Spanish and French – Deepak Kumar May 22 '21 at 11:32
  • @DeepakKumar In this case, I would suggest [edit]ing the question and adding this information. I will retract my vote. – Turing85 May 22 '21 at 11:32
  • Ensure that your _JSON_ is saved using `utf-8` encoding. Open the file in _Notepad++_; I'm pretty sure that its _encoding-fu_ will detect "_ANSI_". – JosefZ May 22 '21 at 12:28
  • This link may help you : https://stackoverflow.com/questions/6352861/json-invalid-utf-8-middle-byte – Harry Coder May 22 '21 at 21:54
  • @JosefZ I am not reading JSON from the file. I am sending it through API call – Deepak Kumar May 24 '21 at 04:58

0 Answers0