activegraph icon indicating copy to clipboard operation
activegraph copied to clipboard

ERROR Failed to generate JSON output. Current context not an ARRAY but OBJECT

Open jordanfowler opened this issue 5 years ago • 4 comments

Running the following code (Geoname is a simple ActiveNode model):

Geoname.find('5666639')

produces (in Ruby):

 Geoname
  MATCH (n:`Geoname`)
  WHERE (n.uuid = {n_uuid})
  RETURN n
  ORDER BY n.uuid
  LIMIT {limit_1} | {:n_uuid=>"5666639", :limit_1=>1}
 HTTP REQUEST: 45ms POST http://graph:7474/db/data/transaction/commit (1 bytes)
Traceback (most recent call last):
        1: from (irb):3
TypeError (no implicit conversion of Symbol into Integer)

and the Neo4j server produces this output:

graph_1  | 2018-09-18 23:36:46.895+0000 ERROR Failed to generate JSON output. Current context not an ARRAY but OBJECT
graph_1  | org.codehaus.jackson.JsonGenerationException: Current context not an ARRAY but OBJECT
graph_1  | 	at org.codehaus.jackson.impl.JsonGeneratorBase._reportError(JsonGeneratorBase.java:480)
graph_1  | 	at org.codehaus.jackson.impl.Utf8Generator.writeEndArray(Utf8Generator.java:354)
graph_1  | 	at org.neo4j.server.rest.transactional.ExecutionResultSerializer.writeRows(ExecutionResultSerializer.java:465)
graph_1  | 	at org.neo4j.server.rest.transactional.ExecutionResultSerializer.statementResult(ExecutionResultSerializer.java:113)
graph_1  | 	at org.neo4j.server.rest.transactional.TransactionHandle.executeStatements(TransactionHandle.java:323)
graph_1  | 	at org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:156)
graph_1  | 	at org.neo4j.server.rest.web.TransactionalService.lambda$executeStatementsAndCommit$1(TransactionalService.java:204)
graph_1  | 	at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
graph_1  | 	at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
graph_1  | 	at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
graph_1  | 	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
graph_1  | 	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
graph_1  | 	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
graph_1  | 	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
graph_1  | 	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
graph_1  | 	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
graph_1  | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)
graph_1  | 	at org.neo4j.server.rest.dbms.AuthorizationDisabledFilter.doFilter(AuthorizationDisabledFilter.java:49)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
graph_1  | 	at org.neo4j.server.rest.web.CorsFilter.doFilter(CorsFilter.java:115)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
graph_1  | 	at org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
graph_1  | 	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
graph_1  | 	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
graph_1  | 	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
graph_1  | 	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317)
graph_1  | 	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
graph_1  | 	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
graph_1  | 	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
graph_1  | 	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
graph_1  | 	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)
graph_1  | 	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
graph_1  | 	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:61)
graph_1  | 	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
graph_1  | 	at org.eclipse.jetty.server.Server.handle(Server.java:531)
graph_1  | 	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
graph_1  | 	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
graph_1  | 	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
graph_1  | 	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
graph_1  | 	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
graph_1  | 	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
graph_1  | 	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
graph_1  | 	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
graph_1  | 	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132)
graph_1  | 	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
graph_1  | 	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
graph_1  | 	at java.lang.Thread.run(Thread.java:748)

Runtime information:

Neo4j database version: 3.4.6 neo4j gem version: 9.3.0 neo4j-core gem version: 8.1.4

jordanfowler avatar Sep 18 '18 23:09 jordanfowler

If I switch to using Bolt protocol, I get: RuntimeError (Unexpected message type: ignored (#<Neo4j::Core::CypherSession::Adaptors::Bolt::Message:0x00005605032e5cd0 @type_code=126, @type=:ignored, @args=[]>))

jordanfowler avatar Sep 19 '18 00:09 jordanfowler

I also have this error. Runtime:

  • database version 3.4.1
  • neo4j gem version 9.3.0
  • neo4j-core version 8.1.4

Further, the node type that is causing this error has a datetime property created using neo4j-admin import. When I retrieve a node using ModelClass.first I get the same error and log output as @jordanfowler. When I retrieve it using session.query I get:

result = sess.query('MATCH (mic:MenuItem) RETURN mic LIMIT 1')
ETHON: performed EASY effective_url=http://localhost:7474/db/data/cypher response_code=400 return_code=ok total_time=0.103544
Traceback (most recent call last):
        1: from (irb):2
Neo4j::Server::CypherResponse::ResponseError (Unsupported property type: class java.time.ZonedDateTime)

There is no error in the log when retrieving using session.query. My other node types do not generate this error on retrieval.

drpump avatar Jan 23 '19 06:01 drpump

I can confirm that removing the datetime property removes the error. Seems that datetime is not yet supported by serialization on the server.

I also tested localdatetime, which gives the same behaviour for ModelClass.first but a slightly different error for session.query:

2.5.1 :003 > result = sess.query('MATCH (mic:MenuItem) RETURN mic LIMIT 1')
ETHON: performed EASY effective_url=http://localhost:7474/db/data/cypher response_code=400 return_code=ok total_time=0.033486
Traceback (most recent call last):
        1: from (irb):3
Neo4j::Server::CypherResponse::ResponseError (Unsupported property type: class java.time.LocalDateTime)

drpump avatar Jan 23 '19 08:01 drpump

Turns out that neo4j 3.5.0 fixes the server issue, providing an iso8601 string for any datetime or localtime properties (my understanding is that iso8601 is now the official datetime format for JSON, so this is a good thing).

Unfortunately, the property type converters in the gem assume an integer value and choke on it.

Workaround is to use type: String for these properties. Also be aware the the Ruby Time.iso8601 parser requires a seconds component in the time string, but Neo4j doesn't provide seconds on datetime properties in JSON even though they're present in the database.

drpump avatar Jan 23 '19 14:01 drpump