GenieFramework/Genie.jl

Choose JSON Renderer due to bug in JSON3/StructTypes

Open

#636 opened on Mar 22, 2023

View on GitHub
 (5 comments) (1 reaction) (1 assignee)Julia (2,408 stars) (186 forks)batch import
enhancementfeature requestgood-first-issuehelp wantednon-breaking

Description

I'm working on an API that needs to serialize a matrix. The JSON.jl package outputs the following

julia> JSON.json(zeros(Float64, 6, 6))
"[[0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0]]"

Which are the results I expect. The JSON3.jl package flattens the array without any information about the original dimensions.

julia> JSON3.write(zeros(Float64, 6, 6))
"[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]"

Because of #304 the Genie JSON renderer uses JSON3, so I have to make my own renderer. The upstream projects have open issues[1][2] to address this unexpected type behavior but it doesn't look like anyone is working them. It would be nice to perhaps add a keyword argument to the Genie renderer to choose which backing package to use.

[1] https://github.com/quinnj/JSON3.jl/issues/196 [2] https://github.com/JuliaData/StructTypes.jl/issues/14

Contributor guide