Search code examples
phpjsonmongodbrestheartwindows-1251

RESTHeart with windows-1251 charset


  • MongoDB server; Text data in windows-1251 charset.
  • RESTHeart server.
  • PHP with window-1251 charset making a request to RESTHeart.
  • Text data is broken

To get text "back" I use this code (from utf-8 to 1251, then from utf-8 to 1251, then back to utf-8, cause json throws an error if encoding is not utf-8):

$body = iconv('CP1251', 'UTF-8', iconv('UTF-8', 'CP1251//IGNORE', iconv('UTF-8', 'CP1251//IGNORE', $body)));

After this $body object contains normal text, but without some chars (not special, like cyrilic 'И').


Solution

  • you can set the charset for the JVM that executes RESTHeart with the -Dfile.encoding property.

    Try something like:

    java -Dfile.encoding=CP1251 -server -jar restheart.jar conf.yml