Skip to content

Commit bf334cf

Browse files
authored
Merge pull request #406 from odow/od/fix-json
Fix serialization of BenchmarkGroup with JSON@1
1 parent 2516b39 commit bf334cf

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BenchmarkTools"
22
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3-
version = "1.6.1"
3+
version = "1.6.2"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/serialization.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...})
2929
return [string(nameof(typeof(x))), d]
3030
end
3131

32+
# Special support is needed for JSON@1, because it doesn't know how to support
33+
# NTuple{N,String} as a dictionary key.
34+
#
35+
# Upstream issue: https://github.com/JuliaIO/JSON.jl/issues/399
36+
#
37+
# This method may be removed if the upstream issue is fixed.
38+
function JSON.lower(x::BenchmarkGroup)
39+
d = Dict{String,Any}(
40+
"data" => Dict(string(k) => v for (k, v) in x.data), "tags" => x.tags
41+
)
42+
return ["BenchmarkGroup", d]
43+
end
44+
3245
# a minimal 'eval' function, mirroring KeyTypes, but being slightly more lenient
3346
safeeval(@nospecialize x) = x
3447
safeeval(x::QuoteNode) = x.value

test/SerializationTests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,11 @@ end
124124
@test BenchmarkTools.load(json_io) == [params]
125125
end
126126

127+
@testset "issue_400_tuple_as_dict_key" begin
128+
grp = BenchmarkTools.BenchmarkGroup()
129+
grp["a", "b"] = BenchmarkTools.BenchmarkGroup()
130+
contents = sprint(io -> BenchmarkTools.save(io, grp))
131+
@test occursin(""""data":{"(\\\"a\\", \\"b\\")":[""", contents)
132+
end
133+
127134
end # module

0 commit comments

Comments
 (0)