Commit 9f4c6e7
committed
fix: JsonTreeWriter accepts finite BigDecimal/BigInteger like JsonWriter
The tree writer's finiteness check used doubleValue(), which can overflow
to Infinity for finite BigDecimal/BigInteger values like 1E400 —
causing toJsonTree to reject inputs that toJson accepts.
JsonWriter.value(Number) already special-cases the
'alwaysCreatesValidJsonNumber' classes (BigDecimal, BigInteger,
AtomicInteger, AtomicLong) to skip the doubleValue-based oracle. This
change mirrors that guard in JsonTreeWriter.value(Number), making the
two writer surfaces agree.
Existing tests (ToNumberPolicyTest, JsonTreeWriterTest, etc.) continue
to pass; the new JsonTreeWriterFiniteBigDecimalTest now passes.1 parent 7fd7de0 commit 9f4c6e7
2 files changed
Lines changed: 6 additions & 28 deletions
File tree
- gson/src
- main/java/com/google/gson/internal/bind
- test/java/com/google/gson/regression
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
221 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
| |||
Lines changed: 0 additions & 27 deletions
This file was deleted.
0 commit comments