Commit 2f2cd4d
John J. Aylward
Fix for number output bug.
java.lang.Number is currently output without any validation. For all java.* Numbers, this is fine, but for custom Number implementations like Complex or Fraction, the resulting JSON output may be invalid.
For example: If a Fraction implementation defines its' toString method as `return numerator + "/" + denominator`, then the resulting JSON output would be something like this:
```json
{ "fraction" : 1/2 }
```
This is not valid JSON.
This commit verifies that the string representation of the number is close to a JSON formatted number by use of the BigDecimal constructor. If the constructor throws a NumberFormatException, then the string value is instead quoted as a string. The example above would instead output like the following:
```json
{ "fraction" : "1/2" }
```1 parent 7232a95 commit 2f2cd4dCopy full SHA for 2f2cd4d
File tree
Expand file treeCollapse file tree
1 file changed
+37
-14
lines changedOpen diff view settings
Filter options
Expand file treeCollapse file tree
1 file changed
+37
-14
lines changedOpen diff view settings
Collapse file
+37-14Lines changed: 37 additions & 14 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
838 | 838 | |
839 | 839 | |
840 | 840 | |
841 | | - |
| 841 | + |
842 | 842 | |
843 | 843 | |
844 | 844 | |
| ||
1693 | 1693 | |
1694 | 1694 | |
1695 | 1695 | |
1696 | | - |
| 1696 | + |
| 1697 | + |
| 1698 | + |
| 1699 | + |
| 1700 | + |
| 1701 | + |
| 1702 | + |
| 1703 | + |
| 1704 | + |
| 1705 | + |
| 1706 | + |
| 1707 | + |
1697 | 1708 | |
1698 | 1709 | |
1699 | 1710 | |
| ||
1783 | 1794 | |
1784 | 1795 | |
1785 | 1796 | |
| 1797 | + |
| 1798 | + |
| 1799 | + |
| 1800 | + |
| 1801 | + |
| 1802 | + |
| 1803 | + |
| 1804 | + |
| 1805 | + |
| 1806 | + |
| 1807 | + |
| 1808 | + |
| 1809 | + |
| 1810 | + |
| 1811 | + |
| 1812 | + |
| 1813 | + |
| 1814 | + |
| 1815 | + |
| 1816 | + |
| 1817 | + |
| 1818 | + |
| 1819 | + |
| 1820 | + |
1786 | 1821 | |
1787 | 1822 | |
1788 | 1823 | |
| ||
1795 | 1830 | |
1796 | 1831 | |
1797 | 1832 | |
1798 | | - |
1799 | | - |
1800 | | - |
1801 | | - |
1802 | | - |
1803 | | - |
1804 | | - |
1805 | | - |
1806 | | - |
1807 | | - |
1808 | | - |
1809 | | - |
1810 | 1833 | |
1811 | 1834 | |
1812 | 1835 | |
|
0 commit comments