Inconsistent `Timestamp` conversion
fbiville opened this issue · comments
Here is a simple program running with the 5.0 JDBC connector for Bolt (affects 4.x versions as well):
public static void main(String[] args) throws SQLException {
BoltDriver boltDriver = new BoltDriver();
Properties props = new Properties();
props.setProperty("username", "neo4j");
props.setProperty("password", "<redacted>");
String query = "WITH datetime('2015-06-24T12:50:35.556+0100') AS zonedDateTime " +
"RETURN zonedDateTime, " +
" [zonedDateTime] AS zonedDateTimeList, " +
" {zonedDateTime: zonedDateTime} AS zonedDateTimeDictionary";
try (Connection connection = boltDriver.connect("jdbc:neo4j:bolt://localhost", props);
ResultSet results = connection.createStatement().executeQuery(query)) {
while (results.next()) {
Object theDateTime = results.getObject("zonedDateTime");
System.out.println(theDateTime.getClass());
theDateTime = ((Iterable<Object>)results.getObject("zonedDateTimeList")).iterator().next();
System.out.println(theDateTime.getClass());
theDateTime = ((Map<String, Object>)results.getObject("zonedDateTimeDictionary")).get("zonedDateTime");
System.out.println(theDateTime.getClass());
}
}
}
Expected behavior
I'd expect the program to print:
class java.sql.Timestamp
class java.sql.Timestamp
class java.sql.Timestamp
Actual behavior
class java.sql.Timestamp
class java.sql.Timestamp
class java.time.ZonedDateTime
This affects maps as well as node/relationship properties.
Fixing this is unfortunately a breaking change.
Next version will do
class java.time.ZonedDateTime
class java.time.ZonedDateTime
class java.time.ZonedDateTime
which I think is correct, when using results.getObject
as baseline.
We decided going down the java.sql.Time|Date|Timestamp
mess only when explicitly asked for.