This example works only in one way - type key is lost trying to convert back to Dict:
abstract type Vehicle end
struct Car <: Vehicle; make::String; model::String; end
struct Truck <: Vehicle; make::String; model::String; payload::Float64; end
# Define how to choose concrete types based on source data
StructUtils.@choosetype Vehicle x -> x["type"] == "car" ? Car : Truck
# Now make can create the right type
car = StructUtils.make(Vehicle, Dict("type" => "car", "make" => "Toyota", "model" => "Corolla"))
StructUtils.make(Dict, car) # no type key
What is the recommended way to make type field working both ways?
Should we always define @nonstruct with custom lift/lower methods?
This example works only in one way -
typekey is lost trying to convert back to Dict:What is the recommended way to make
typefield working both ways?Should we always define
@nonstructwith customlift/lowermethods?