Havunen / SystemTextJsonPatch

SystemTextJsonPatch is a JSON Patch (JsonPatchDocument) RFC 6902 implementation for .NET using System.Text.Json
MIT License
102 stars 12 forks source link

"JsonPatchTestOperationException: The value '1000' is invalid for target location." for nullable valuetype-props #32

Closed Rgaroth closed 2 months ago

Rgaroth commented 2 months ago

Consider the following minimalistic test:

[Fact]
public void Test()
{
    Class1 obj = new();
    var sourcePatch = new JsonPatchDocument<Class1>().Replace(c => c.Id, 1000);
    var deserealizedPatch = JsonSerializer.Deserialize<JsonPatchDocument<Class1>>(JsonSerializer.Serialize(sourcePatch));

    sourcePatch.ApplyTo(obj); // success
    deserealizedPatch.ApplyTo(obj); // JsonPatchTestOperationException: The value '1000' is invalid for target location.
}

public class Class1
{
    public int? Id { get; set; }
}

When I try to patch a NULLABLE property by deserialized JsonPatchDocument, I get an error JsonPatchTestOperationException: The value '1000' is invalid for target location

Havunen commented 2 months ago

Hi,

This sounds like a bug. I will take a look

Havunen commented 2 months ago

The test case you provided here does not reproduce the error? Do you maybe have incorrect using statement or something similar in the real code?

Havunen commented 2 months ago

CI run also green: https://github.com/Havunen/SystemTextJsonPatch/commit/06aaa858171e986a02d6787449e32c0961eb84d1

Rgaroth commented 2 months ago

Yes, it was a custom converter JsonConverter in JsonSerializerOptions, i am sorry...