json.go 614 B

12345678910111213141516171819202122232425262728293031
  1. package mhayaSerializer
  2. import (
  3. jsoniter "github.com/json-iterator/go"
  4. )
  5. type JSON struct{}
  6. func NewJSON() *JSON {
  7. return &JSON{}
  8. }
  9. // Marshal returns the JSON encoding of v.
  10. func (j *JSON) Marshal(v interface{}) ([]byte, error) {
  11. if data, ok := v.([]byte); ok {
  12. return data, nil
  13. }
  14. return jsoniter.Marshal(v)
  15. }
  16. // Unmarshal parses the JSON-encoded data and stores the result
  17. // in the value pointed to by v.
  18. func (j *JSON) Unmarshal(data []byte, v interface{}) error {
  19. return jsoniter.Unmarshal(data, v)
  20. }
  21. // Name returns the name of the serializer.
  22. func (j *JSON) Name() string {
  23. return "json"
  24. }