Golang encoding/json.Marshaler type examples

package encoding/json

Golang encoding/json.Marshaler type usage examples

Example 1:

 type Cmd interface {
  json.Marshaler
  json.Unmarshaler
  Id() interface{}
  Method() string
 }

Example 2:

 type Stats struct {
  Field string `json:"field"`
  Aggregations map[string]json.Marshaler `json:"aggregations,omitempty"`
 }

Example 3:

 marshalerType := reflect.TypeOf((*json.Marshaler)(nil)).Elem()

Reference :

http://golang.org/pkg/encoding/json/#Marshaler

Advertisement