Skip to content

Commit

Permalink
Add lowering fallback for Real subtypes that converts to Float64 (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfrr authored and TotalVerb committed Oct 5, 2016
1 parent 0e36473 commit 6b08c8d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/JSON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ end
lower(c::Char) = string(c)
lower(d::DataType) = string(d)
lower(m::Module) = throw(ArgumentError("cannot serialize Module $m as JSON"))
lower(x::Real) = Float64(x)

const INDENT=true
const NOINDENT=false
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DataStructures
FixedPointNumbers
3 changes: 3 additions & 0 deletions test/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ JSON.lower{T}(v::Type151{T}) = Dict(:type => T, :value => v.x)
@test JSON.parse(JSON.json(Type151(1.0))) == Dict(
"type" => "Float64",
"value" => 1.0)

fixednum = Fixed{Int16, 15}(0.1234)
@test JSON.parse(JSON.json(fixednum)) == Float64(fixednum)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using JSON
using Base.Test
using Compat
import DataStructures
import FixedPointNumbers: Fixed

include("json-checker.jl")
include(joinpath(dirname(@__FILE__),"json_samples.jl"))
Expand Down

0 comments on commit 6b08c8d

Please sign in to comment.