I'm trying to create a neo4j native datetime type (https://neo4j.com/docs/cypher-manual/current/syntax/temporal/) with spring data neo4j. I have a rest controller which takes an object as parameter, this object is then directly saved to neo4j.
I skip the rest controller, I'll give later the implementation of the object.
I'm using
and all packages with <groupId>org.neo4j</groupId> use version 3.2.2.
I'm using the following pieces of forum and documentation :
Based on this, I wrote an object and a no op converter:
MyObject:
public class MyObject{
@Convert(NoOpZonedDateTimeConversion.class)
private ZonedDateTime testDate;
// + getter and setter
}
NoOpZonedDateTimeConversion :
public class NoOpZonedDateTimeConversion implements AttributeConverter<LocalDateTime, LocalDateTime> {
@Override
public LocalDateTime toGraphProperty(LocalDateTime value) {
return value;
}
@Override
public LocalDateTime toEntityAttribute(LocalDateTime value) {
return value;
}
}
This registers a string in my database (neo 3.5.5-enterprise).
I tried a few converters with various native java date type, I tried without converter, simple question : is it suppose to work or am I missing something ?
You have to opt-in to enable the native type support. More details in this great blog post (section Native types support) written by @michael.simons.
The key ingredient is to add (assuming you are using bolt protocol) the native type support dependency
Thanks for the help, so far I did not succeed to register a ZonedDateTime native java object in the database as a neo4j DateTime.
I'm using spring boot and I enabled native types in my application.yml. I also added the maven dependancy neo4j-ogm-bolt-native-types.
My NodeEntity has a ZonedateTime private parameter with accessors.
I'm posting a json with this date : "1996-10-15T00:05:32.000Z" and I end up with 1996-10-15T00:05:32[UTC] in the database. I suspect that it might also be a problem with spring boot deserialization of java date types, I'll have to investigate but that will be for another time I'm afraid.
I have a property in a node entity with getters and setters LocalDateTime date;
And I can now register LocalDateTime directly in my DB which is great necause I have access to all methods and tools of Date and Time in neo4j (better than String imo)