Thanks, all. I presumed it was something like that -- I can definitely see how it gets tricky to decide the right default behavior in this case. We've actually settled on using a different pattern that makes the JSON prettier and easier to switch on, which I've seen come up elsewhere on the group. FWIW, I actually really like it, even though it's a bit non-obvious at first:
type Message struct {
Type string
First *FirstSubtype `json:"omitempty"`
Second *SecondSubtype `json:"omitempty"`
}
type FirstSubtype struct {
Something string
}
type SecondSubtype struct {
SomethingElse string
}
This is nice because you end up with slightly clearer JSON and you can switch on the type and dispatch more easily:
switch msg.Type {
case "first":
doSomethingWith(msg.First)
case "second":
doSomethingElseWith(msg.Second)