How to pass a DateTime value as parameter in Java Driver for Neo4J?

357 Views Asked by At

I am using the Neo4J Java driver

<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>4.2.0</version>
</dependency>

And I am trying to use a DateTime value as value in a parameter map roughly like this:

// we have a timezone, unixTimestamp as epoch seconds and a simple key: "d"
final Instant instant = Instant.ofEpochSecond(unixTimestamp);
final ZoneId zoneId = ZoneId.of(timezone);
final ZonedDateTime zonedValueDate = ZonedDateTime.ofInstant(instant, zoneId);
// creating a DateTimeValue from zonedValueDate does not work either
return Map.of(key, zonedValueDate);

This map is used in an instance of TransactionWork like

public Map<String,Object> execute(Transaction tx) {
    Result queryResult = tx.run(query, parameter);
    // consuming results ...
    // returning them as Map
}

But I am getting an exception:

org.neo4j.driver.exceptions.ClientException: Property values can only be of primitive types or arrays thereof

A DateTime or ZonedDateTime should be allowed as parameter (here is another hint), but how can it be used correctly?

Or do I HAVE to create a DateTime value like this:

datetime({year:1984, month:10, day:11, hour:12, timezone: 'Europe/Stockholm'})
0

There are 0 best solutions below