Announcement Announcement Module
No announcement yet.
[Neo4j] Issues persisting a List/Set/Array of byte array Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Neo4j] Issues persisting a List/Set/Array of byte array

    Hi Everyone,

    I ran into some issues with byte array.

    I was able to successfully persist and read "byte[]" in neo4j database.
    I verified them using neoeclipse (a graph database viewer) and found they are appearing as byte[] datatype.

    Next I tried to persist List<byte[]> or Set<byte[]> or byte[][]. (i.e., [[1,2,3], [4,5,6]....] )
    After persisting, I found all of them are appearing as String[] (i.e., [ "1,2,3", "4,5,6", ... ] ) in the database.
    When I read them back I was able to read them if I had persisted them as List<byte[]> or Set<byte[]>. However in case of byte[][], it was throwing a spring framework exception (Cannot convert String to byte array), while reading back.

    I have 2 questions
    1) Does spring data framework support higher dimensional arrays yet?
    2) Since the List<byte[]> and Set<byte[]> can be successfully persisted and read back, are they converting String "1,2,3" to byte[] [1,2,3] automatically internally ? Is it really supported by Spring data and can I safely use them ?

    Thanks in advance

  • #2

    Firstly, Neo4j support simple types (boolean, int, long, double, String etc) and arrays of simple types (int[], float[] etc). SDN supports those directly too, as well as enums and java.util.Date, additionally.

    For other types - MyFooBar or long[][][][][], we delegate to Spring's conversion support, specifically GenericConversionService (, which is configurable outside of SDN itself. This is the same conversion support you get for other Spring services, it is a Spring Core library.

    So if you want to store custom types you need to go and write your own converters and install them, and here is an example of how to do that:




    • #3
      Thanks Lasee for your reply.

      One other question: I want to persist something like List of Objects. What kind of data structure will be useful in this case ?
      Set wont work as they don't preserve the sequence.

      And how do we make sure that the converter i wrote (for converting byte[] to string/long etc) on lets say List<byte[]> not a regular byte[].


      • #4
        Write a converter of your objects to strings (json) or byte[] (java serialization).

        Otherwise you can also decompose your objects into node-entities and create a linked list of those.