I have a structure that I would like to efficiently encode JSON:
type MyStruct struct { *Meta Contents []interface{} } type Meta struct { Id int }
The structure contains metadata of a known form and contents of an unknown form. The content list is populated at run time, so I really don't control them. To improve the speed of sorting Go, I would like to implement the Marshaller interface over the Meta structure. The Marshaller interface is as follows:
type Marshaler interface { MarshalJSON() ([]byte, error) }
Please keep in mind that the meta structure is not as simple as shown here. I tried to implement the Marshaler interface over the Meta structure, but it seems that when I then JSON marshal MyStruct, the result will be only the result returned by the Meta marshalling interface.
So my question is: how can I create a JSON structure containing an inline structure with my own JSON marshaller and another structure without one?
source share