JolPatchDocument Access ICollection

I am trying to replace an object in a list using JsonPatchDocument, but I get an exception when I try to access a collection member with the correct path, here is my code:

    var oppfour = new Operation<Application>("replace", "/comments/0", "", obj);

    var contractResolver = new DefaultContractResolver();
    var operations = new List<Operation<Application>>();

    operations.Add(operation);
    operations.Add(opptwo);
    operations.Add(oppthree);
    operations.Add(oppfour);

    var patchJson = new JsonPatchDocument<Application>(operations, contractResolver);

    try
    {
        patchJson.ApplyTo(app);
    }

      

the data model I'm trying to access looks like this:

public class Application: BaseEntity
{
    public virtual ICollection<Comment> Comments { get; set; }
}

      

Here's an exception:

Microsoft.AspNetCore.JsonPatch.Exceptions.JsonPatchException: The target location specified by path segment '0' was not found.

How can I set the path to replace something at a specific point in the collection?

+3


source to share





All Articles