gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/encoders/json.go (about)

     1  package encoders
     2  
     3  import "encoding/json"
     4  
     5  // jsonEncoder implements Marshaller for the JSON format.
     6  type jsonEncoder struct{}
     7  
     8  // Marshal returns the JSON encoding of v.
     9  func (jsonEncoder) Marshal(v interface{}) ([]byte, error) {
    10  	return json.Marshal(v)
    11  }
    12  
    13  // Unmarshal parses the JSON-encoded data and stores the result
    14  // in the value pointed to by v. If v is nil or not a pointer,
    15  // Unmarshal returns an InvalidUnmarshalError.
    16  func (jsonEncoder) Unmarshal(data []byte, v interface{}) error {
    17  	return json.Unmarshal(data, v)
    18  }
    19  
    20  // JSON holds a json encoder instance implementing Marshaller.
    21  var JSON Marshaller = &jsonEncoder{}