Skip to content

Deserialization depends on lexicographical ordering of types #296

@simsurace

Description

@simsurace

This is unexpected and may be a bug.

using JSON3, StructTypes

struct Type1
    name::String
    n::Int
end

struct Type2
    name::String
end

struct Type3
    name::String
    n::Int
end

json_string = """
    [
        {
            "name": "test",
            "n": 1
        },
        {
            "name": "test"
        }
    ]
    """

JSON3.read(json_string, Vector{Union{Type1,Type2}}) # [Type1("test", 1), Type2("test")]
JSON3.read(json_string, Vector{Union{Type3,Type2}}) # [Type2("test"), Type2("test")]

The parsing as Type2 in the second example drops one field of the json data.

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