JSON2.jl icon indicating copy to clipboard operation
JSON2.jl copied to clipboard

Error loading zero-dim array

Open JackDunnNZ opened this issue 6 years ago • 0 comments

The following example breaks because the zero-dim array isn't handled correctly.

import JSON2
struct A
    a::Array{Int,0}
end

a = A(zeros(Int))

JSON2.read(JSON2.write(a), A)

gives

ERROR: MethodError: no method matching Array{Int64,0}(::Array{Any,1})
Closest candidates are:
  Array{Int64,0}(::AbstractArray{S,N}) where {T, N, S} at array.jl:472
  Array{Int64,0}(::Any) where T<:AbstractArray at abstractarray.jl:22
  Array{Int64,0}(::UndefInitializer, ::Int64...) where {T, N} at boot.jl:400
  ...
Stacktrace:
 [1] Array{Int64,0}(::Array{Any,1}) at ./abstractarray.jl:22
 [2] read(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Type{Array{Int64,0}}) at /Users/jack/.julia/packages/JSON2/FSRl/src/read.jl:176
 [3] macro expansion at /Users/jack/.julia/packages/JSON2/FSRl/src/read.jl:287 [inlined]
 [4] read(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Type{A}) at /Users/jack/.julia/packages/JSON2/FSRl/src/read.jl:464
 [5] read(::String, ::Type) at /Users/jack/.julia/packages/JSON2/FSRl/src/read.jl:50
 [6] top-level scope at none:0

I'm not entirely sure if it should be fixed on the reading/writing side (or both)

JackDunnNZ avatar Jul 26 '18 14:07 JackDunnNZ