-1

For most applications deployed for Canadian users, we need to support both English and French at the same time. By default, light-4j applications will return ?? for French chars in the JSON response. How to handler the French response?

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
Steve Hu
  • 358
  • 2
  • 10
  • Possible duplicate of [Why content type header to use for json? "application/json; charset=utf-8 " or "application/json"?](https://stackoverflow.com/questions/19814908/why-content-type-header-to-use-for-json-application-json-charset-utf-8-or) – Raedwald Sep 27 '19 at 10:34
  • [JSON is always UTF-8 encoded](https://stackoverflow.com/a/19815111/545127) and thus can have French characters. – Raedwald Sep 27 '19 at 10:35
  • Please provide either a relevant source code excerpt, or a network trace. – Julian Reschke Sep 27 '19 at 14:41
  • FWIW, it's a bit strange to ask a question and then to immediately reply to it. – Julian Reschke Sep 30 '19 at 14:58

1 Answers1

-2

You might need to set the encoder in the response header in the case the ByteBuffer is used. When the response is String, then there is no need to specify it is UTF-8 as it is the default for JSON. The other option is to encode the bytes in UTF-8 before putting them into the ByteBuffer. The answer is specific for Undertow/Light-4j Server.

Exchange.setResponseHeaders(Headers.CONTENT_TYPE, “application/json;charset=utf-8”)

UTF-8 is the format

Steve Hu
  • 358
  • 2
  • 10
  • 1
    application/json doesn't have a charset parameter – Julian Reschke Sep 26 '19 at 19:16
  • According to this post, https://stackoverflow.com/questions/9254891/what-does-content-type-application-json-charset-utf-8-really-mean the charset is not necessary for JSON but still valid as part of the content type. – Steve Hu Sep 27 '19 at 14:25
  • The parameter is undefined for application/json. It's not supposed to have an effect. It's pointless to send it. – Julian Reschke Sep 27 '19 at 14:39