Loading and writing data using GraphSON

How to load and write GraphSON data.

The Tinkerpop GraphSON Reader can be used to load and write data.

Procedure

  1. Start the Gremlin console.
  2. Start a graph instance and create the schema.
  3. Use the DSE Graph Loader to load the GraphSON file.
  4. Writing data out of the graph into a GraphSON file while capturing the original data types of the inserted data can be accomplished with a short script:
    gremlin> f = new FileOutputStream("/tmp/recipe_lossless.json");
    mapper = graph.io(graphson()).mapper().embedTypes(true).create(); 
    graph.io(graphson()).writer().mapper(mapper).create().writeVertex(f,g.V().next(),BOTH) 
    ==>null

    A sample of the output shows the class information and data types:

    {
      "@class":"java.util.HashMap",
      "id":{
        "@class":"java.util.HashMap",
        "~label":"meal",
        "member_id":["java.lang.Long",25],
        "community_id":1989847424
      },
      "label":"meal",