thank you for your response, and also for your work in general on Jooq! Funny that this issue is 9 years old and sorry for not being able to find it.
Actually, during serialization, I am fine with DateTime.toString() method being used since it produces the standard ISO8601 format. Not being able to read it back and import was my problem. I am not sure how to do it with the listener API.
Anyways, since I was not missing something and it is a literal feature request to be implemented, I went with the following approach:
1. Create a private/internal Converter for Timestamp <-> String, where String is ISO8601:
private static class IsoTimestampConverter extends AbstractConverter<String, Timestamp> {
private IsoTimestampConverter() {
super(String.class, Timestamp.class);
}
@Override
public Timestamp from(String str) {
if (StringUtils.isEmpty(str)) {
return null;
}
return Timestamp.from(Instant.parse(str));
}
@Override
public String to(Timestamp ts) {
return ts == null ? null : ts.toString();
}
}2. using
.fields(Field<?>... fields) with Loader API where I go over the fields of the table and use my custom
IsoTimestampConverter, if that particular field is a timestamp field:
private List<Field<?>> getTableFields(Table<?> table) {
return Arrays.stream(table.fields())
.map(it -> {
if (it.getDataType().isTimestamp()) {
return DSL.field(it.getName(), SQLDataType.VARCHAR(50)).convert(isoTimestampConverter);
} else {
return it;
}
}).toList();
}such that the actual usage becomes
.fields(getTableFields(table)).
I was looking for a general solution, where I do not hardcode decisions for each table and its fields, since my tables and columns can change over time.
The full solution is at
https://github.com/steve-community/steve/pull/1874/commits/747d863fee58616d7976aff9de64c7d8a03d95e4 if anyone is interested.
Regards,
Sevket