Announcement Announcement Module
No announcement yet.
Neo4J: Write custom converters to save non-primitives as node-properties Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neo4J: Write custom converters to save non-primitives as node-properties


    i want to use joda-time[1] as Datetime-Lib for handling date/time-purposes within my J2EE-App. Additional, i want to save a "Currency" as a node-property:

    import org.joda.time.DateTime;
    import java.util.Currency;
    public class Company{
      protected DateTime createdAt;
      protected Currency currency;
    Both values, "createdAt" and "currency", are not saved to the graph.

    The Spring Data Neo4J-Documentation[2] explains me the reason: The values are not primitive, and i guess there are not spring-converters for them. So I'd like to wirte converters for this types, how can I do this?

    Btw. both types are serializable[3][4] - does spring data neo4j not try to save properties by serializing/unserializing properties, if there are non-primitive but implement Serializable?

    I am using Sprint data neo4j 2.1RC2 in standalone-mode.


    Last edited by MarkusSchulte; Aug 17th, 2012, 05:40 AM.

  • #2
    AFAIK, custom conversion is still buggy. If you search SDN JIRA, you will find some issues related to it.

    BTW, I also tried using Joda-Time lib, and no success. In the mean time, I perform custom conversion in my getters/setters, whereas the mapped field in my domain class is plain long primitive, and it has to be named differently than getter/setter,


    • #3

      As you said, this should work, as documented in

      However, currently you can only convert to String and back (see And also you have to manually register your converter, something like:
          static class TestConfig extends Neo4jConfiguration {
              GraphDatabaseService graphDatabaseService() {
                  return new ImpermanentGraphDatabase();
              protected ConversionService neo4jConversionService() throws Exception {
                  ConversionService conversionService = super.neo4jConversionService();
                  conversionService.addConverter(new MyAwesomeConverter());
                  conversionService.addConverter(new MyAwesomeReverseConverter());
                  return conversionService;
      However, monitor the jira ticket for updates.


      • #4

        thanks to your replies. I decided to implement as vmarcinko suggests - for time IMO the easiest way. But not the cleanest.

        Btw, the Issue will be resolved in RC3.


        • #5
          ... And RC3 came out literally an hour ago

          Happy hacking!