runarorama/argonaut — pull request #1 by tixxit (2014-12-05 00:22:22+00:00)
Title: Support all valid JSON numbers

This adds 2 new subtypes for `JsonNumber`:

* `JsonDecimal` - an "arbitrary" JSON number type. It represents the JSON number as a String, since not all valid JSON numbers can be represented as a BigDecimal. It will lazily convert to `BigDecimal` and `Double` on demand.
* `JsonBigDecimal` - a wrapper for `BigDecimal` values for completeness.

It also speeds up parsing numbers. If the number is a valid `Long`, then we will parse the value and stuff it in a `JsonLong`. Otherwise we stuff the (valid) number in a `JsonDecimal`. This has the effect of speeding up parsing by delaying the conversion (we only verify the number is valid). It also avoids the need to worry about whether people want `Double`s or `BigDecimal`s when they parse, since they'll only pay the parsing overhead for the types they use.

This also implements a non-trivial normalization scheme to compare `JsonDecimal`s for semantic equality (and implement `hashCode` on `JsonNumber`).