From f28c6e78a9b2af6c87a22cb03e7c3fbc6e98c7bc Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Fri, 5 May 2017 07:53:58 +0200 Subject: [PATCH] Fix show_json(A::AbstractArray{T,0}) (#184) Writes the first element of A. --- src/Writer.jl | 3 +++ test/serializer.jl | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/Writer.jl b/src/Writer.jl index 374d1db..3c3e434 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -312,6 +312,9 @@ function show_json{T,n}(io::SC, s::CS, A::AbstractArray{T,n}) end_array(io) end +# special case for 0-dimensional arrays +show_json{T}(io::SC, s::CS, A::AbstractArray{T,0}) = show_json(io, s, A[]) + show_json(io::SC, s::CS, a) = show_json(io, s, lower(a)) # Fallback show_json for non-SC types diff --git a/test/serializer.jl b/test/serializer.jl index 57f0dbe..040954d 100644 --- a/test/serializer.jl +++ b/test/serializer.jl @@ -87,4 +87,7 @@ let filename = tempname() rm(filename) end +# issue #184: serializing a 0-dimensional array +@test sprint(JSON.show_json, JSON.StandardSerialization(), view([184], 1)) == "184" + end