Commit 677413f
Fix WriteJsonScalar for programmatically-created JsonValue numerics
JsonValue.Create(T) preserves the exact CLR type it was created from,
so TryGetValue<T> does a strict type match against it - unlike a
JsonNode.Parse()-produced JsonValue (backed by a flexible JsonElement
that widens across numeric types). WriteJsonScalar only probed bool/
long/double/string, so a value created via JsonValue.Create(3) (int),
JsonValue.Create(3f) (float), or a plain `new JsonObject { ["x"] = 3 }`
assignment matched none of those checks and threw. Verified this
empirically (JsonValue.Create(3)/Create(3.5f)/Create((short)3) each
only satisfy TryGetValue of their own exact type) before fixing.
Now probes every CLR numeric type JsonValue.Create supports (int,
short, sbyte, byte, ushort, uint, ulong alongside the existing long;
float, decimal alongside the existing double) and widens to the
matching Write(long)/Write(double) overload. Added a regression test
building a JsonObject via plain property assignment (not
JsonNode.Parse) to cover this path, since the existing round-trip
test's JsonNode.Parse-backed values didn't exercise it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 0fdeaf3 commit 677413f
2 files changed
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
609 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
610 | 624 | | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
611 | 628 | | |
612 | 629 | | |
613 | 630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
657 | 697 | | |
658 | 698 | | |
659 | 699 | | |
| |||
0 commit comments