generated from quinnj/Example.jl
-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
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 keyWhat is the recommended way to make type field working both ways?
Should we always define @nonstruct with custom lift/lower methods?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels