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

Parsing into a Union of enums

Open wmanning-cra opened this issue 3 years ago • 0 comments

Thanks for the quick response on the other Union issue. I actually found a new one: parsing into a union of multiple enums does not work.

julia> @enum E A=1 B=2
julia> @enum e a=1 b=2
julia> JSON3.read("\"a\"", e)
 a::e = 1
julia> JSON3.read("\"a\"", Union{E, e})
 ERROR: MethodError: no method matching namemap(::Type{Union{E, e}})
 Closest candidates are:
     namemap(::Type{Dates.AMPM}) at Enums.jl:193
     namemap(::Type{JSON3.Error}) at Enums.jl:193
     namemap(::Type{LibGit2.Consts.GIT_OPT}) at Enums.jl:193
     ...
Stacktrace:
 [1] construct(::Type{Union{E, e}}, ::Symbol) at C:\Users\wmanning\.julia\packages\StructTypes\NJXhA\src\StructTypes.jl:427
 [2] construct(::Type{Union{E, e}}, ::Ptr{UInt8}, ::Int64) at C:\Users\wmanning\.julia\packages\StructTypes\NJXhA\src\StructTypes.jl:420
 [3] read(::StructTypes.StringType, ::Base.CodeUnits{UInt8,String}, ::Int64, ::Int64, ::UInt8, ::Type{Union{E, e}}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\wmanning\.julia\packages\JSON3\IvnMR\src\structs.jl:123
 [4] read(::StructTypes.StringType, ::Base.CodeUnits{UInt8,String}, ::Int64, ::Int64, ::UInt8, ::Type{Union{E, e}}) at C:\Users\wmanning\.julia\packages\JSON3\IvnMR\src\structs.jl:99
 [5] read(::String, ::Type{Union{E, e}}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\wmanning\.julia\packages\JSON3\IvnMR\src\structs.jl:34
 [6] read(::String, ::Type{Union{E, e}}) at C:\Users\wmanning\.julia\packages\JSON3\IvnMR\src\structs.jl:33
 [7] top-level scope at REPL[18]:1

wmanning-cra avatar Aug 04 '21 00:08 wmanning-cra