Skip to content

Why are keys of a Dict not unpacked before serialization? #286

Closed
@simsurace

Description

@simsurace

Is this intentional? Values of a dict are unpacked before serialization, but keys are not:

using JSON3, StructTypes

struct IntWrapper
    val::Int
end

StructTypes.StructType(::Type{IntWrapper}) = StructTypes.NumberType()
StructTypes.numbertype(::Type{IntWrapper}) = Int
Base.Int(id::IntWrapper) = id.val

JSON3.write(IntWrapper(42)) == "42" # true
JSON3.write(Dict(IntWrapper(42) => 42)) == "{\"42\":42}" # false
JSON3.write(Dict(42 => IntWrapper(42))) == "{\"42\":42}" # true

Am I missing something or is this a bug?

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