Implement both JsonMarshaler and JsonUnmarshaler

If a type only defines one-half of the symmetry (e.g. it implements MarshalJSON() but not UnmarshalJSON() ), then that type doesn't satisfy the codec encoding/decoding check and instead codec will not encode or decode the item using the special interface methods.
This commit is contained in:
Tobie Morgan Hitchcock 2017-11-24 10:55:13 +00:00
parent b96cdc79dc
commit 527f85f8e6

View file

@ -77,6 +77,10 @@ func (d *Doc) MarshalJSON() ([]byte, error) {
return json.Marshal(d.Data()) return json.Marshal(d.Data())
} }
func (d *Doc) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &d.data)
}
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
func (d *Doc) path(path ...string) (paths []string) { func (d *Doc) path(path ...string) (paths []string) {