json.go 808 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. import "encoding/json"
  6. // JSONInterface represents an interface to handle json data
  7. type JSONInterface interface {
  8. Marshal(v interface{}) ([]byte, error)
  9. Unmarshal(data []byte, v interface{}) error
  10. }
  11. var (
  12. // DefaultJSONHandler default json handler
  13. DefaultJSONHandler JSONInterface = StdJSON{}
  14. )
  15. // StdJSON implements JSONInterface via encoding/json
  16. type StdJSON struct{}
  17. // Marshal implements JSONInterface
  18. func (StdJSON) Marshal(v interface{}) ([]byte, error) {
  19. return json.Marshal(v)
  20. }
  21. // Unmarshal implements JSONInterface
  22. func (StdJSON) Unmarshal(data []byte, v interface{}) error {
  23. return json.Unmarshal(data, v)
  24. }