You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add JSON3.tostring for Real number overloads when writing (#236)
* Add `JSON3.tostring` for Real number overloads when writing
This is the best idea I can come up with to address
#232. First a summary of the problem,
* We allow custom number types to overload `StructTypes.numbertype` that we
convert to before writing JSON
* However, we only provide JSON writing routines for `Integer` and `AbstractFloat`
* So a number like `3//2` (`Rational`) or `π` (`Irrational`) which are both `<: Real`,
but not `Integer` or `AbstractFloat` we get the stack overlfow behavior reported above
The proposal here then is we first check if a `Real` has overloaded `StructTypes.numbertype`
and _if not_, we'll use a new `JSON3.tostring` method, which by default converts the custom
number to `Float64` and then calls `Base.string(x)`. This method allows custom number types,
like FixedPointDecimal, to overload `JSON3.tostring` to provide an appropriate string representation
for their type.
* add tostring to docs
0 commit comments