For reference I'm attaching my custom binding in case anyone runs into this in the future.
package storage.jooq.bindings;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.Objects;
import org.jooq.Binding;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingGetSQLInputContext;
import org.jooq.BindingGetStatementContext;
import org.jooq.BindingRegisterContext;
import org.jooq.BindingSQLContext;
import org.jooq.BindingSetSQLOutputContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.impl.DSL;
/**
* Support for PostgreSQL's INTERVAL datatype adapted from the GSON example at:
*
https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings/ */
@SuppressWarnings("serial")
public class PostgresIntervalBinding implements Binding<Object, String> {
// The converter does all the work
@Override
public Converter<Object, String> converter() {
return new Converter<Object, String>() {
@Override
public String from(Object t) {
return t == null ? null : t.toString();
}
@Override
public Object to(String u) {
return u == null ? null : u;
}
@Override
public Class<Object> fromType() {
return Object.class;
}
@Override
public Class<String> toType() {
return String.class;
}
};
}
// Rending a bind variable for the binding context's value and casting it to the interval type
@Override
public void sql(BindingSQLContext<String> ctx) throws SQLException {
// Depending on how you generate your SQL, you may need to explicitly distinguish
// between jOOQ generating bind variables or inlined literals. If so, use this check:
// ctx.render().paramType() == INLINED
ctx.render().visit(DSL.val(ctx.convert(converter()).value())).sql("::interval");
}
@Override
public void register(BindingRegisterContext<String> ctx) throws SQLException {
ctx.statement().registerOutParameter(ctx.index(), Types.OTHER);
}
// Converting the JsonNode to a String value and setting that on a JDBC PreparedStatement
@Override
public void set(BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement().setString(ctx.index(), Objects.toString(ctx.convert(converter()).value(), null));
}
@Override
public void get(BindingGetResultSetContext<String> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
}
@Override
public void get(BindingGetStatementContext<String> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
}
@Override
public void set(BindingSetSQLOutputContext<String> ctx) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public void get(BindingGetSQLInputContext<String> ctx) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
}