Home > Blockchain >  Neo4jClient Create is including a JsonIgnore property
Neo4jClient Create is including a JsonIgnore property

Time:12-17

I have a C# class with simple properties I am expecting to be saved to a Node when I call create. When I build the query using Neo4jClient 5.1.3, a complex class that is decorated with [JsonIgnore] is included in the CREATE command.

Here is a Person class:

public class Person {
        public string FirstName { get; set; }
        public string LastName { get; set; }    
        public string Email { get; set; }

        [JsonIgnore]
        public Organization Employer { get; set; }

}

I'm creating an instance of it:

        var person = new Person
        {
            Email = "[email protected]",
            FirstName = "Job",
            LastName = "Bob",
            Employer = previouslyCreatedEmployer,
        };

...and when I run this:

            var query = neo.Client.Cypher
                .Create("(p:Person:Security $object)")
                .WithParams(new Dictionary<string, object> {
                    { "object", person }
                })
                ;

the QueryTextForDebug is this:

CREATE (p:Person:Security {
  Email: "[email protected]",
  FirstName: "Job",
  LastName: "Bob",
  Employer: {
    Logo: "",
    IxId: "89becda5-98b4-4623-928f-4c6580cd554f",
    name: "Joe's Bakery"
  },
  IxId: "eb117b37-b062-40e1-b038-1749156ecf7a"
})

Since I had the JsonIgnore tag on Employer in class definition I was not expecting it to be included. What am I missing? And thank you.

Side thought... maybe I SHOULDN'T have the JsonIgnore tag in there so I can write nicer queries, right?

CodePudding user response:

Neo4jClient v5.1.3 depends on Newtonsoft.Json, check that JsonIgnore comes from this library and not from System.Text.Json, or specify full type name including namespace:

public class Person 
{
    [Newtonsoft.Json.JsonIgnore]
    public Organization Employer { get; set; }
}
  • Related