Jooq does not currently support JSR 310 types and support will not appear until v3.8 .
Using simple converters generally works, except for certain types, such as postgres' TIMESTAMP WITH TIME ZONE , which requires custom binding. So I tried to write one, but the generated XxxRecord classes still use the Timestamp data type for the TIMESTAMP WITH TIME ZONE fields in my database.
What do I need to change in my code below to see postgres' TIMESTAMP WITH TIME ZONE as Instant in jooq generated classes?
Converter
public class TimestampConverter implements Converter<Timestamp, Instant> { @Override public Instant from(Timestamp ts) { return ts == null ? null : ts.toInstant(); } @Override public Timestamp to(Instant instant) { return instant == null ? null : Timestamp.from(instant); } @Override public Class<Timestamp> fromType() { return Timestamp.class; } @Override public Class<Instant> toType() { return Instant.class; } }
Custom binding
public class TimestampBinding implements Binding<Timestamp, Instant> { private static final Converter<Timestamp, Instant> converter = new TimestampConverter(); private final DefaultBinding<Timestamp, Instant> delegate = new DefaultBinding<> (converter()); @Override public Converter<Timestamp, Instant> converter() { return converter; } @Override public void sql(BindingSQLContext<Instant> ctx) throws SQLException { delegate.sql(ctx); }
pom.xml (excerpts)
<customType> <name>java.time.Instant</name> <type>java.time.Instant</type> <binding>xxx.TimestampBinding</binding> </customType> ... <forcedType> <name>java.time.Instant</name> <types>timestamp with time zone</types> </forcedType>
source share