Closed stonepreston closed 3 years ago
In order to signal than any subtype of AbstractSystem
should be CustomStruct
, you just need to change your definition to:
StructTypes.StructType(::Type{<:ModelingToolkit.AbstractSystem}) = StructTypes.CustomStruct()
alternatively, and perhaps more clear, you could define it as:
StructTypes.StructType(::Type{T}) where {T <: ModelingToolkit.AbstractSystem} = StructTypes.CustomStruct()
they both mean the same thing, but essentially you're doing a lower-bound constraint on ModelingToolkit.AbstractSystem
and saying, "any type that is ModelingToolkit.AbstractSystem or lower". In your original definition, the method only matched when the ModelingToolkit.AbstractSystem
abstract type itself was passed in, but not its subtypes.
Hope that helps.
That did it! Thanks so much
Hello. I'm very new to julia and am trying to use your package in conjunction with JSON3 to do some serialization of an abstract type. Originally I used JSON.jl but stumbled across this package which has the very cool feature of being able to write json to a Type so I am trying to switch over to JSON3.
With JSON.jl, I could specify a lowering function on an abstract type (in this case I am taking in an abstract type and wrapping it in a simple wrapper type called System:
That works fine and nothing else is needed.
With JSON3 however I found that in addition to registering the abstract type as a custom struct, I also have to register the sub types:
if the system passed in to lower is of type ODESystem (or any other subtype of AbstractSystem) then I have to provide that CustomStruct type mapping for that. Is that normal? Am I doing something wrong?