Issue comparing decimals in JsonPatch tests
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
1. If an existing decimal value is `1.0M` and a patch document has a test value of `1` then there is no error when applying the test.
2. If an existing decimal value is `1.00M` and a patch document has a test value of `1` then the test fails with the message:
`The current value '1.00' at path 'decimal' is not equal to the test value '1'.`
I believe the behaviour in scenario 1 is correct because APIs should be liberal in what they accept; a consumer of the API shouldn't be told that 1.0 doesn't equal 1, which would seem quite pedantic.
Based on this, I feel like scenario 2 is a bug. We have a lot of database columns which have this precision and it makes them harder to patch. Are there any workarounds?
Minimal repro (for scenario 2, easy to tweak for scenario 1)
```C#
{
var incomingOperations = new[]
{
new Operation
{
op = "test",
path = "/decimal",
value = 1
},
new Operation
{
op = "replace",
path = "/decimal",
value = 2
}
};
var incomingJson = JsonConvert.SerializeObject(incomingOperations);
var document = JsonConvert.DeserializeObject>(incomingJson);
var existingEntity = new Test { Decimal = 1.00M };
document.ApplyTo(existingEntity, x => Debug.WriteLine(x.ErrorMessage));
}
public class Test
{
public decimal Decimal { get; set; }
}
```
Using 3.1
Contributor guide
Assessment
This issue has not been assessed yet.