Using jOOQ's Converter or Binding
I'm assuming this is about JSON and PostgreSQL? See also: org.jooq.exception.DataAccessException: unsupported Unicode escape sequence \u0000
It seems that a Converter<JSON, JSON> (or JSONB, respectively) would suffice?
Converter.ofNullable(JSON.class, JSON.class,
j -> j,
j -> JSON.json(j.data().replace("\\u0000", ""))
);
And then, attach that everywhere using a forcedType:
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.17.0.xsd">
<generator>
<database>
<forcedTypes>
<forcedType>
<userType>org.jooq.JSON</userType>
<converter>Converter.ofNullable(JSON.class, JSON.class,
j -> j,
j -> JSON.json(j.data().replace("\\u0000", ""))
)</converter>
<includeTypes>(?i:json)</includeTypes>
</forcedType>
</forcedTypes>
</database>
</generator>
</configuration>
Using JDBC
You could, of course, also just proxy JDBC and patch PreparedStatement::setString:
@Override
public void setString(int parameterIndex, String x) throws SQLException {
if (x == null)
delegate.setString(parameterIndex, x);
else
delegate.setString(parameterIndex, x.replace("\\u0000", "");
}
// Also all the other methods that might accept strings
A simple way to approach this is by using jOOQ's own JDBC proxy utility types, to avoid implementing the entire JDBC API:
This will handle things on a lower level, including when you don't use jOOQ. However, if you're using inline values, then those won't be converted by this approach, as those values are transparent to JDBC