Unlike a Converter, a Binding dictates how your data type is being handled at the JDBC level within jOOQ, without jOOQ knowing about your implementation. I.e., not only will you define how to convert between and types (T = database type, U = user type), but you will also be able to define how such types are:
Rendered as SQL
Bound to PreparedStatements
Bound to SQLOutput
Registered in CallableStatements as OUT parameters
Fetched from ResultSets
Fetched from SQLInput
Fetched from CallableStatements as OUT parameters
An example Binding for use with Jackson to produce JsonNode types is given here:
public class PostgresJSONJacksonJsonNodeBinding
implements Binding
And the Converter that is used above can be seen here:
public class PostgresJSONJacksonJsonNodeConverter
implements Converter {
@Override
public JsonNode from(Object t) {
try {
return t == null
? NullNode.instance
: new ObjectMapper().readTree(t + "");
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Object to(JsonNode u) {
try {
return u == null || u.equals(NullNode.instance)
? null
: new ObjectMapper().writeValueAsString(u);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Class fromType() {
return Object.class;
}
@Override
public Class toType() {
return JsonNode.class;
}
}
You can now register the above binding via the code generator configuration: