From 570412bb97fa008fe8d5872bbb375c777dd18de8 Mon Sep 17 00:00:00 2001 From: Fengyang Wang <fengyang.wang.0@gmail.com> Date: Fri, 12 May 2017 23:26:09 -0700 Subject: [PATCH] Add support for serializing Set --- src/Writer.jl | 1 + test/standard-serializer.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Writer.jl b/src/Writer.jl index de670d1..48bc97a 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -54,6 +54,7 @@ lower(x::IsPrintedAsString) = x lower(m::Module) = throw(ArgumentError("cannot serialize Module $m as JSON")) lower(x::Real) = Float64(x) +lower(x::Base.AbstractSet) = collect(x) """ Abstract supertype of all JSON and JSON-like structural writer contexts. diff --git a/test/standard-serializer.jl b/test/standard-serializer.jl index c63eb8f..0e82176 100644 --- a/test/standard-serializer.jl +++ b/test/standard-serializer.jl @@ -57,3 +57,8 @@ end #Multidimensional arrays @test json([0 1; 2 0]) == "[[0,2],[1,0]]" end + +@testset "Sets" begin + @test json(Set()) == "[]" + @test json(Set([1, 2])) in ["[1,2]", "[2,1]"] +end