Fabio Kfouri
Fabio Kfouri

Reputation: 63

Deserialize Json from Neo4J 2.2.2

I´m using the Neo4J version 2.2.2.

When the Neo4jClient try to deserialize the following json (Mode Projection) we receive the following message:

Neo4j returned a valid response, however Neo4jClient was unable to deserialize into the object structure you supplied. First, try and review the exception below to work out what broke. Include the full text of this exception, including this message, the stack trace, and all of the inner exception details. Include the full type definition of VB$AnonymousType_0`2[[Person, App_Code.tynn6afz, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null],[Movie, App_Code.tynn6afz, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].

Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:

{
    "columns": [
        "person",
        "movie"
    ],
    "data": [
        [
            {
                "outgoing_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/out",
                "labels": "http://sjkdv37:7474/db/data/node/324/labels",
                "data": {
                    "born": 1956,
                    "name": "Tom Hanks"
                },
                "all_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/all/{-list|&|types}",
                "traverse": "http://sjkdv37:7474/db/data/node/324/traverse/{returnType}",
                "self": "http://sjkdv37:7474/db/data/node/324",
                "property": "http://sjkdv37:7474/db/data/node/324/properties/{key}",
                "properties": "http://sjkdv37:7474/db/data/node/324/properties",
                "outgoing_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/out/{-list|&|types}",
                "incoming_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/in",
                "extensions": {},
                "create_relationship": "http://sjkdv37:7474/db/data/node/324/relationships",
                "paged_traverse": "http://sjkdv37:7474/db/data/node/324/paged/traverse/{returnType}{?pageSize,leaseTime}",
                "all_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/all",
                "incoming_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/in/{-list|&|types}",
                "metadata": {
                    "id": 324,
                    "labels": [
                        "Person"
                    ]
                }
            },
            {
                "outgoing_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/out",
                "labels": "http://sjkdv37:7474/db/data/node/364/labels",
                "data": {
                    "released": 2006,
                    "title": "The Da Vinci Code",
                    "tagline": "Break The Codes"
                },
                "all_typed_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/all/{-list|&|types}",
                "traverse": "http://sjkdv37:7474/db/data/node/364/traverse/{returnType}",
                "self": "http://sjkdv37:7474/db/data/node/364",
                "property": "http://sjkdv37:7474/db/data/node/364/properties/{key}",
                "properties": "http://sjkdv37:7474/db/data/node/364/properties",
                "outgoing_typed_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/out/{-list|&|types}",
                "incoming_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/in",
                "extensions": {},
                "create_relationship": "http://sjkdv37:7474/db/data/node/364/relationships",
                "paged_traverse": "http://sjkdv37:7474/db/data/node/364/paged/traverse/{returnType}{?pageSize,leaseTime}",
                "all_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/all",
                "incoming_typed_relationships": "http://sjkdv37:7474/db/data/node/364/relationships/in/{-list|&|types}",
                "metadata": {
                    "id": 364,
                    "labels": [
                        "Movie"
                    ]
                }
            }
        ],
        [
            {
                "outgoing_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/out",
                "labels": "http://sjkdv37:7474/db/data/node/324/labels",
                "data": {
                    "born": 1956,
                    "name": "Tom Hanks"
                },
                "all_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/all/{-list|&|types}",
                "traverse": "http://sjkdv37:7474/db/data/node/324/traverse/{returnType}",
                "self": "http://sjkdv37:7474/db/data/node/324",
                "property": "http://sjkdv37:7474/db/data/node/324/properties/{key}",
                "properties": "http://sjkdv37:7474/db/data/node/324/properties",
                "outgoing_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/out/{-list|&|types}",
                "incoming_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/in",
                "extensions": {},
                "create_relationship": "http://sjkdv37:7474/db/data/node/324/relationships",
                "paged_traverse": "http://sjkdv37:7474/db/data/node/324/paged/traverse/{returnType}{?pageSize,leaseTime}",
                "all_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/all",
                "incoming_typed_relationships": "http://sjkdv37:7474/db/data/node/324/relationships/in/{-list|&|types}",
                "metadata": {
                    "id": 324,
                    "labels": [
                        "Person"
                    ]
                }
            },
            {
                "outgoing_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/out",
                "labels": "http://sjkdv37:7474/db/data/node/414/labels",
                "data": {
                    "released": 2004,
                    "title": "The Polar Express",
                    "tagline": "This Holiday Season… Believe"
                },
                "all_typed_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/all/{-list|&|types}",
                "traverse": "http://sjkdv37:7474/db/data/node/414/traverse/{returnType}",
                "self": "http://sjkdv37:7474/db/data/node/414",
                "property": "http://sjkdv37:7474/db/data/node/414/properties/{key}",
                "properties": "http://sjkdv37:7474/db/data/node/414/properties",
                "outgoing_typed_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/out/{-list|&|types}",
                "incoming_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/in",
                "extensions": {},
                "create_relationship": "http://sjkdv37:7474/db/data/node/414/relationships",
                "paged_traverse": "http://sjkdv37:7474/db/data/node/414/paged/traverse/{returnType}{?pageSize,leaseTime}",
                "all_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/all",
                "incoming_typed_relationships": "http://sjkdv37:7474/db/data/node/414/relationships/in/{-list|&|types}",
                "metadata": {
                    "id": 414,
                    "labels": [
                        "Movie"
                    ]
                }
            }
        ]
    ]
}

EDIT

I'm including the VB Code, but I think this error is generated by Neo4jClient.

Perhaps the error is around the ParseInProjectionMode function at CypherJsonDeserializer.cs

Dim user As String = "neo4j"
Dim pwd As String = "password" 
Dim server As String = "localhost:7474"
Dim link As String = "http://{0}:{1}@{2}/db/data"
Dim url As New Uri(String.Format(link, user, pwd, server))

Dim client As New GraphClient(url)
client.Connect()

Dim query = client.Cypher _
    .Match("(p:Person {name: ""Tom Hanks""})-[:ACTED_IN]->(m:Movie)") _
    .Return(Function(p, m) New With {
                .person = p.As(Of Person)(), _
                .movie = m.As(Of Movie)()
            })

'Here the client threw an Exception

For Each item In query.Results
    Dim temp As String = String.Format("{0} - {1}<br>", item.movie.title, item.movie.released)
    divOut.InnerHtml += temp
Next

In additional, I created theses classes.

Public Class Movie
    Public Property title As String
    Public Property released As Integer
    Public Property tagline As String
End Class

Public Class Person
    Public Property name As String
    Public Property born As Integer
End Class

Upvotes: 0

Views: 629

Answers (1)

Charlotte Skardon
Charlotte Skardon

Reputation: 6270

The error is stemming from the Anonymous type you're creating, now, I don't pretend to know why, and without spending some time digging through the Neo4jClient codebase - it'd be hard to find out exactly.

You can get around this by using concrete classes this example works and puts out the data to the screen (and I want to point out, I am no vb coder, so excuse silly errors):

Module Module1
    Private Class Together
        Public Property Person As Person
        Public Property Movie As Movie
    End Class

    Sub Main()
        Dim user = "neo4j"
        Dim pwd = "password"
        Dim server = "localhost:7474"
        Dim link = "http://{0}:{1}@{2}/db/data"
        Dim url As New Uri(String.Format(link, user, pwd, server))

        Dim client As New GraphClient(url)
        client.Connect()

        Dim query = New CypherFluentQuery(client) _
                .Match("(p:Person {name: ""Tom Hanks""})-[:ACTED_IN]->(m:Movie)") _
                .Return(Function(p, m) New Together With {
                    .Person = p.As(Of Person)(), _
                    .Movie = m.As(Of Movie)()
                })

        Dim results = query.Results.ToList()

        For Each item In results

            Dim temp As String = String.Format("{0} - {1}<br>", item.Movie.title, item.Movie.released)
            Console.WriteLine(temp)

        Next
        Console.ReadLine()
    End Sub

End Module

With your classes defined as you already have them.

You could try fixing this in the Neo4jClient codebase and issuing a pull request (which would be good), and if you really need this, for the moment you're probably going to want to get the code and use your own compiled version rather than nuget as active development seems to be paused for a small spell.

PS. It is vb specific, C# is quite happy with anonymous types for this, so maybe some way anonymous types are handled in VB which is unrecognised in the codebase.

Upvotes: 1

Related Questions