Skip to content

Commit

Permalink
Add support for serializing Set
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed May 13, 2017
1 parent 0690cfb commit 570412b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions test/standard-serializer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 570412b

Please sign in to comment.