Search code examples
javajsonlinuxpostgresqljdbi

Control characters in resultSet string


We have a correct and clean json string in a text column in Postgres, this string is a sort of configuration data rarely changed.

The json string is fetched from java code running in a web application on wildfly via jdbi query.

Only on linux systems we experience the presence of control characters (?) when reading the string from resultSet (with a getString("param_value")). Here the json text saved after the read from resultSet.

Any suggestion?


Solution

  • I don't know WHY this happen, but i've tested the code in unit test with the same results obtained in application server environment (windows ok, linux ko). Furthermore, nothing changes after both postgres jdbc driver and jdbi driver upgrade.

    As WORKAROUND to avoid problems when parsing json, a string replace of control character is performed:

    String jsonString = resultSet.getString("param_value")
                          .replaceAll("[\\x00-\\x1F\‌​\x7F\\x0A\\xfffd\\x2‌​0a]","");
    

    The sequence of control character was initially taken from this post, then extended based on json parsing exception messages.