Files
go-pkg/serialize/json.go
2022-03-04 17:24:23 +08:00

18 lines
329 B
Go

package serialize
import "encoding/json"
type jsonSerializer struct{}
func JSON() Serializer {
return jsonSerializer{}
}
func (js jsonSerializer) Encode(v interface{}) (data []byte, err error) {
return json.Marshal(v)
}
func (js jsonSerializer) Decode(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}