Given the following structs
type UpdateConcert struct {
FullConcert FullConcert
Fields map[string]interface{}
}
type FullConcert struct {
DomConcert *dom.Concert
DomSingerID string `json:"domSingerID"`
DomSingerGroupID string `json:"domSingerGroupID"`
}
With the dom.Concert being too large to post but contains int64, int, more nested struct slices, strings, string slices, and time pointers for a total of 90 fields on the dom.Concert (not including the lower nested structs). Also, all json tags are present on both the dom.Concert as well as all nested structs on it.
When doing:
var arrayToUnmarshalInto []UpdateConcert
var bytes []byte
bytes, err = json.Marshal(concerts)
if err != nil {
return errors.Wrap(err, "Failed to marshal concerts")
}
byteLength := len(bytes)
str := string(bytes[:byteLength])
err = json.Unmarshal(bytes, &arrayToUnmarshalInto)
if err != nil {
return errors.Wrap(err, "Failed to unmarshal concerts")
}
fmt.Printf("%v", str)
fmt.Printf("%v", arrayToUnmarshalInto)
return nil
While using the standard json.Marshal from the "encoding/json" package we can get a valid byte slice back, and when casting to a string from the byte slice we see the expected stringified JSON. However, the arrayToUnmarshalInto produces an empty slice. And when inspecting an individual UpdateConcert struct we see only default values and nil. However, when iterating over a map[string]inteface{} that we have unmarshaled into, we can successfully print all values.
How would one go about writing a custom unmarshal for such a varied and deeply nested struct?