Skip to content

StructTypes.excludes not working #224

@trigaten

Description

@trigaten

I have a struct which I am trying to save as a JSON. I would like to exclude one of its fields. StructTypes.excludes seems like the proper way to do this, but I getting the below error when using it. What might be going wrong?

MRE

using JSON3

mutable struct example_struct
    x
    y
    z
    example_struct() = new(1,2,3)
end

StructTypes.StructType(::Type{example_struct}) = StructTypes.Mutable()
StructTypes.excludes(::Type{example_struct}) = (:x)

ex = example_struct()

JSON3.write(ex)
ERROR: MethodError: no method matching symbolin(::Symbol, ::Symbol)
Closest candidates are:
  symbolin(::Union{Bool, Tuple{Vararg{Symbol}}}, ::Any) at ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:604
Stacktrace:
 [1] foreachfield
   @ ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:634 [inlined]
 [2] #write#74
   @ ~/.julia/packages/JSON3/GoF7x/src/write.jl:132 [inlined]
 [3] write
   @ ~/.julia/packages/JSON3/GoF7x/src/write.jl:130 [inlined]
 [4] write(obj::example_struct; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ JSON3 ~/.julia/packages/JSON3/GoF7x/src/write.jl:39
 [5] write(obj::example_struct)
   @ JSON3 ~/.julia/packages/JSON3/GoF7x/src/write.jl:37
 [6] top-level scope
   @ REPL[28]:1
 [7] top-level scope
   @ ~/.julia/packages/CUDA/DfvRa/src/initialization.jl:52

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions