mirror of
https://github.com/pyihe/go-pkg.git
synced 2025-10-03 23:26:33 +08:00
28 lines
420 B
Go
28 lines
420 B
Go
package jsonserialize
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/pyihe/go-pkg/serialize"
|
|
)
|
|
|
|
const Name = "json"
|
|
|
|
func init() {
|
|
serialize.Register(&jsCodec{})
|
|
}
|
|
|
|
type jsCodec struct{}
|
|
|
|
func (js *jsCodec) Name() string {
|
|
return Name
|
|
}
|
|
|
|
func (js *jsCodec) Marshal(v interface{}) ([]byte, error) {
|
|
return json.Marshal(v)
|
|
}
|
|
|
|
func (js *jsCodec) Unmarshal(data []byte, v interface{}) error {
|
|
return json.Unmarshal(data, v)
|
|
}
|