JSON3.write expects the output of pairs to have length defined
non-Jedi opened this issue · comments
Adam B commented
The pairs
function from Base is only required to return an iterator, but if you define e.g. JSON3.StructType(::Type{MyType}) = JSON3.ObjectType()
and Base.pairs(x::MyType) = Iterators.filter(isnothing∘last, ("foo" => "bar", "foobar" => nothing))
, JSON3.write
throws a MethodError:
MethodError: no method matching length(::Base.Iterators.Filter{Base.var"#56#57"{Base.var"#58#59"{typeof(isnothing)},typeof(last)},Base.Generator{NTuple{6,Symbol},MatrixProtocolClient.var"#11#12"{MatrixProtocolClient.LoginBody{MatrixProtocolClient.UserIdentifier}}}})
Closest candidates are:
length(!Matched::Core.SimpleVector) at essentials.jl:593
length(!Matched::Base.MethodList) at reflection.jl:849
length(!Matched::Core.MethodTable) at reflection.jl:923
...
Stacktrace:
[1] #write#68(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(JSON3.write), ::JSON3.ObjectType, ::Array{UInt8,1}, ::Int64, ::Int64, ::MatrixProtocolClient.LoginBody{MatrixProtocolClient.UserIdentifier}) at /home/adam/.julia/packages/JSON3/ItGdr/src/write.jl:129
[2] write(::JSON3.ObjectType, ::Array{UInt8,1}, ::Int64, ::Int64, ::MatrixProtocolClient.LoginBody{MatrixProtocolClient.UserIdentifier}) at /home/adam/.julia/packages/JSON3/ItGdr/src/write.jl:127
[3] #write#55(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(JSON3.write), ::MatrixProtocolClient.LoginBody{MatrixProtocolClient.UserIdentifier}) at /home/adam/.julia/packages/JSON3/ItGdr/src/write.jl:24
[4] write(::MatrixProtocolClient.LoginBody{MatrixProtocolClient.UserIdentifier}) at /home/adam/.julia/packages/JSON3/ItGdr/src/write.jl:22
[5] top-level scope at In[26]:1
JSON3 v0.1.13