-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Labels
Description
Hi, firstly thanks for the package, really cool :)
I've noticed when trying to implement the JSON3 plumbing for parametric types, JSON3.write
doesn't include the subtype key in its output if it's not a field name? This means that the round trip of writing and then reading back in some parametric structs won't work as expected (unless in my understanding you make the sub type key a field?) . E.g.
using JSON3
using StructTypes
struct A{T}
x::T
end
StructTypes.StructType(::Type{A}) = StructTypes.AbstractType()
StructTypes.StructType(::Type{A{T}}) where T = StructTypes.Struct()
StructTypes.subtypekey(::Type{A}) = :_type
# just define this for one type for this example
StructTypes.subtypes(::Type{A}) = NamedTuple{ (Symbol("A{Float64}"),)}( (A{Float64}))
# errors
a = A{Float64}(1.0)
JSON3.read(JSON3.write(a), A)
Since in our use case we'd like to be able to automatically define this plumbing purely based on the parametric type T
, it would be great to automatically include the subtype key in the write code rather than expect it to be a field?
Thanks alot!