neo4j-contrib / gremlin-plugin

A Plugin for the Neo4j server add Tinkerpop-related functionality
Other
55 stars 23 forks source link

Serialization of a list of maps fails with an exception #7

Closed ghost closed 11 years ago

ghost commented 11 years ago

Executing the following query leads to an exception:

x = [];
g.v( 1 ).out.transform{
                 m = [:];
                 m.putAll( it.map() );
                 m.put( "id", it.id );
                 m
                }.fill(x);
x

Exception:

{
  "message":"Invalid list type: map",
  "exception":"IllegalStateException",
  "stacktrace":
  [
    "org.neo4j.server.rest.repr.RepresentationFormat.serializeList(RepresentationFormat.java:65)",
    "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:50)",
    "org.neo4j.server.rest.repr.OutputFormat.assemble(OutputFormat.java:179)",
    "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:131)",
    "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:117)",
    "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:55)",
    "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:122)",
    "java.lang.reflect.Method.invoke(Method.java:597)"
  ]
}

see http://stackoverflow.com/questions/15571058/extract-map-from-vertex-and-return-an-array-of-maps-via-rest-api for further details

ghost commented 11 years ago

Possible Unit-Test for this issue: Extend org.neo4j.server.plugin.gremlin.GremlinPluginTest with

@Test
public void testExecuteScriptSerializeMapInList() throws Exception
{
    JSONArray array = (JSONArray) parser.parse( json.assemble(GremlinPluginTest.executeTestScript( "x=[];g.v(1).out.transform{m=[id:it.id];m.putAll(it.map());m}.fill(x)", null)));
    Assert.assertEquals(
            ( (JSONObject) array.get( 0 ) ).get( "name" ), "vadas" );
    Assert.assertEquals(
            ( (JSONObject) array.get( 1 ) ).get( "name" ), "josh" );
    Assert.assertEquals(
            ( (JSONObject) array.get( 2 ) ).get( "name" ), "lop" );
}