Results 1 to 5 of 5

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

  1. #1

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

    Hi,

    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:

    Code:
    import org.joda.time.DateTime;
    import java.util.Currency;
    
    @NodeEntity
    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.

    Greetz,
    Markus

    [1] http://joda-time.sourceforge.net/
    [2] http://static.springsource.org/sprin...e/html/#d5e825
    [3] http://joda-time.sourceforge.net/apidocs/index.html
    [4] http://docs.oracle.com/javase/6/docs.../Currency.html
    Last edited by MarkusSchulte; Aug 17th, 2012 at 05:40 AM.

  2. #2

    Default

    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. #3
    Join Date
    May 2012
    Posts
    107

    Default

    Markus,

    As you said, this should work, as documented in http://static.springsource.org/sprin...e/html/#d5e825.

    However, currently you can only convert to String and back (see https://jira.springsource.org/browse/DATAGRAPH-286). And also you have to manually register your converter, something like:
    Code:
    @Configuration
        @EnableNeo4jRepositories
        static class TestConfig extends Neo4jConfiguration {
            @Bean
            GraphDatabaseService graphDatabaseService() {
                return new ImpermanentGraphDatabase();
            }
    
            @Bean
            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. #4

    Default

    Hi,

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

    Btw, the Issue https://jira.springsource.org/browse/DATAGRAPH-286 will be resolved in RC3.

  5. #5
    Join Date
    May 2012
    Posts
    107

    Default

    ... And RC3 came out literally an hour ago

    Happy hacking!

    Lasse

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •