I have this:

type Runner interface {
TaskName() string
Run(ctx context.Context) error
}

type Job struct {
Tasks []Runner
}

1. I have number of structs that implement Runner interface and get added 
into slice of Tasks.

2. I use json.Encoder to save Job into JSON file.

3. But when I try to load JSON back via json.Decoder I get error:
"json: cannot unmarshal object into Go struct field Job.Tasks of type 
serv.Runner"
I guess unmarshaller does not have enough information in saved JSON to 
restore specific 
structs. 

Question: what would be right design decision? Add extra metadata to 
structs that 
implement Runner and restore structs manually via type assertion of 
interface{} during load?

Thanks a lot for any help.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to