Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: relax order requirement for StructTypes.Struct() #69

Closed
chris-b1 opened this issue Jul 31, 2020 · 1 comment
Closed

Discussion: relax order requirement for StructTypes.Struct() #69

chris-b1 opened this issue Jul 31, 2020 · 1 comment

Comments

@chris-b1
Copy link

This isn't a bug, as it is well documented, but I wanted to raise the possibility of changing this behavior. Possibly related to #47 Simple example

using JSON3
using StructTypes

struct Foo
    a::Int64
    b::Int64
end
StructTypes.StructType(::Type{Foo}) = StructTypes.Struct()

julia> JSON3.read("""{"b": 1, "a": 2}""", Foo).a
1 # oops!

The two issues I see are

  • (in my opinion) - breaks principle of least surprise. Using the "default" julia type (struct) with a JSON parser (unordered), implicitly requires ordered data
  • Forces uses of mutable structs to safely interact with JSON3

That all said I don't know how technically feasible this is - naively I would think because you know the field order of Foo, the parser could re-order data as it receives it to match, but assume this would at minimum cost some performance.

@quinnj
Copy link
Owner

quinnj commented Feb 25, 2021

Strict order requirements for Struct have been lifted as of #113

@quinnj quinnj closed this as completed Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants