diff --git a/src/json3.jl b/src/json3.jl index 9cb0a65..3e03c8e 100644 --- a/src/json3.jl +++ b/src/json3.jl @@ -8,3 +8,6 @@ const StructTypes = JSON3.StructTypes StructTypes.StructType(::Type{<:PlotlyBase.Plot}) = JSON3.RawType() JSON3.rawbytes(plot::PlotlyBase.Plot) = codeunits(JSON.json(plot)) + +StructTypes.StructType(::Type{<:HasFields}) = JSON3.RawType() +JSON3.rawbytes(x::HasFields) = codeunits(JSON.json(x)) \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml index 2cfb8c8..0364274 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,4 +2,5 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" +JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/json.jl b/test/json.jl new file mode 100644 index 0000000..427c56e --- /dev/null +++ b/test/json.jl @@ -0,0 +1,13 @@ + +gt = PlotlyBase.GenericTrace("scatter"; x=1:10, y=(1:10).^2) +pplot = PlotlyBase.Plot(gt) +layout = PlotlyBase.Layout() + +using PlotlyBase.JSON, JSON3 + +@testset "Convert to json" begin + @test JSON.json(gt) == "{\"y\":[1,4,9,16,25,36,49,64,81,100],\"type\":\"scatter\",\"x\":[1,2,3,4,5,6,7,8,9,10]}" + @test JSON.json(gt) == JSON3.write(gt) + @test JSON.json(pplot) == JSON3.write(pplot) + @test JSON.json(layout) == JSON3.write(layout) +end