Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshaling empty matrix results in ERROR: MethodError: no method matching #40

Open
szafna opened this issue Apr 9, 2022 · 0 comments

Comments

@szafna
Copy link

szafna commented Apr 9, 2022

Hi
it looks there is an corner case not supported with unmarshal.
It happens where an empty Matrix is unmarshaled. A JSON matrix value [] is parsed to Any[]. Next, the unmarshaling of the form
Unmarshal.unmarshal(Matrix{Int32}, Any[]) returns Any[]. Note that: typeof(Any[]) returns Vector{Any}. However, constructor for Matrix expects the type Matrix{Any}

MWE demonstrates this:

struct test
    id::Int32
    cs::Array{Int32,2} 
end

julia> d1=test(3, reshape([],0,0))
test(3, Matrix{Int32}(undef, 0, 0))

julia> d2=JSON.json(d1)
"{\"id\":3,\"cs\":[]}"

julia> d3=JSON.parse(d2)
Dict{String, Any} with 2 entries:
  "cs" => Any[]
  "id" => 3

julia> d4=Unmarshal.unmarshal(test,d3,true)
test AbstractDict
\--> id <: Int32
\--> cs <: Matrix{Int32}
        Array{Int32, 2}
ERROR: MethodError: no method matching Matrix{Int32}(::Vector{Any})
Closest candidates are:
  Array{T, N}(::AbstractArray{S, N}) where {T, N, S} at C:\Programs\Julia-1.7.0\share\julia\base\array.jl:563
  Matrix{T}(::LinearAlgebra.UpperTriangular) where T at C:\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\LinearAlgebra\src\triangular.jl:177
  Matrix{T}(::LinearAlgebra.UpperHessenberg) where T at C:\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\LinearAlgebra\src\hessenberg.jl:68
  ...

I'd be glad if this could be fixed.

Simon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant