Solution 1: Using jsr310 as the error said.
Not recommended. If it's for an existing interface and upgrading the driver causes issues(mysql5.7 to mysql8.0.2x or clickhouse driver to newrver version whose driver class is com.clickhouse.x), using this solution may result in formatting issues during serialization.
For example:
If the meta field type is java.sql.TIMESTAMP, the serialization result changes.
Originally, the JSON serialized format was yyyy-MM-dd HH:mm:ss.
With the new driver, the object type returned is LocalDateTime. When using this module, the JSON serialized value will have the format 2025-02-18T15:33:52.541, causing a change in the format.
Example 2:
If the meta field type is java.sql.Date, the serialization result remains the same.
Originally, in the lower version, the JSON serialized format was yyyy-MM-dd.
With the new driver, the returned object type is LocalDate. The serialized value format remains consistent with the lower version.
Solution 2: You can manually handle field parsing to keep the behavior consistent with the lower version, as per your needs.
public static Object extractData(ResultSetMetaData meta, ResultSet rs, int index) throws SQLException {
int type = meta.getColumnType(index);
switch (type) {
// JAVA_OBJECT is typically used for complex types like Map
case Types.JAVA_OBJECT:
case Types.ARRAY:
case Types.STRUCT:
return rs.getString(index);
// Handle TIMESTAMP type
case Types.TIMESTAMP:
Object object = rs.getObject(index);
if (object instanceof LocalDateTime) {
// Default: use system time zone
return Date.from(((LocalDateTime) object).atZone(ZoneId.systemDefault()).toInstant());
} else {
return object;
}
// Handle DATE type (convert LocalDate to java.sql.Date)
case Types.DATE:
Object dateObject = rs.getObject(index);
if (dateObject instanceof LocalDate) {
return java.sql.Date.valueOf((LocalDate) dateObject);
} else {
return dateObject;
}
// For all other types, return the object as is
default:
return rs.getObject(index);
}
}