Skip to content

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

Closed

Description

@Rgaroth

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

Activity

  1. changed the title [-]JsonPatchTestOperationException: The value '1000' is invalid for target location. for nullable [/-] [+]"JsonPatchTestOperationException: The value '1000' is invalid for target location." for nullable valuetype-props[/+] on Aug 6, 2024
  2. Havunen commented on Aug 7, 2024

    @Havunen
    Owner

    Hi,

    This sounds like a bug. I will take a look

  3. Havunen commented on Aug 7, 2024

    @Havunen
    Owner

    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?

  4. added a commit that references this issue on Aug 7, 2024
  5. Havunen commented on Aug 7, 2024

    @Havunen
    Owner

    CI run also green: 06aaa85

  6. Rgaroth commented on Aug 7, 2024

    @Rgaroth
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions