confusedstudent
confusedstudent

Reputation: 395

Retreiveing Relationship in Neoj4Client gives Deserialization exception

I'm trying to retrieve a relationship with an attribute from my DB. I'm using Neo4jClient and .NET . This is what I've tried so far :

var client = new GraphClient(new Uri("http://localhost:11007"), "neo4j", "jobsjobs");
var JsonContractResolver = new CamelCasePropertyNamesContractResolver();
client.ConnectAsync().Wait();
var createQuery = client.Cypher
                        .Match("matched=(a:Technology{name:{to},title:{level}})<-[rel:HOP]-(b:Technology{name:{from},title:{level}})")
                        .WithParam("to", "ArangoDB")
                        .WithParam("level", "Junior")
                        .WithParam("from", "Big Table")
                        .Return(rel => rel.As<RelationshipInstance<Hop>>()).ResultsAsync;

foreach (var item in createQuery.Result)
{
    Console.WriteLine(item.Data.Cost);
}

This is my 'Hop' relationship class:

 public class Hop : Relationship,
    IRelationshipAllowingSourceNode<Technology>,
    IRelationshipAllowingTargetNode<Technology>
 {

    [JsonProperty("cost")]
    public long? Cost { get; set; }
    public Hop() : base(-1, null) { }
    public Hop(NodeReference targetNode) : base(targetNode)
    {
    }

    public const string TypeKey = "HOP";

    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }

This is the error that I've been getting for the past 6 hours:

"One or more errors occurred. (Neo4j returned a valid response, however Neo4jClient was unable to deserialize into the object structure you supplied.\r\n\r\nFirst, try and review the exception below to work out what broke.\r\n\r\nIf it's not obvious, you can ask for help at http://stackoverflow.com/questions/tagged/neo4jclient\r\n\r\nInclude the full text of this exception, including this message, the stack trace, and all of the inner exception details.\r\n\r\nInclude the full type definition of <>f__AnonymousType11[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].\r\n\r\nInclude this raw JSON, with any sensitive values replaced with non-sensitive equivalents:\r\n\r\n (Parameter 'content')) " at Neo4jClient.Serialization.CypherJsonDeserializer1.Deserialize(String content, Boolean isHttp)\r\n at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync[TResult](CypherQuery query)" "

EDIT : Adding the JSON format of the HOP relationship :

{ "identity": 1515, "start": 1495, "end": 1491, "type": "HOP", "properties": { "cost": 3 } }

This is the JSON format of the nodes:

{ "identity": 1491, "labels": [ "Technology" ], "properties": { "name": "ArangoDB", "title": "Junior" } }

This is the results in graph format

Upvotes: 0

Views: 119

Answers (1)

Charlotte Skardon
Charlotte Skardon

Reputation: 6270

With the relationships, to get the properties, you just need to supply a standard POCO, so instead of your Hop class, you should go for:

public class Hop
{
    [JsonProperty("cost")]
    public long? Cost {get;set;}
}

which changes your query to:

var createQueryTask = client
    .Cypher
    .Match("matched=(a:Technology{name:{to},title:{level}})<-[rel:HOP]-(b:Technology{name:{from},title:{level}})")
    .WithParams(new { to = "ArangoDB", level = "Junior", from = "Big Table"})
    .Return(rel => rel.As<Hop>()).ResultsAsync;

Upvotes: 1

Related Questions