2019-06-23 17:22:43 +02:00
|
|
|
// Copyright 2019 The Xorm Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-03-22 16:12:55 +01:00
|
|
|
package json
|
2019-06-23 17:22:43 +02:00
|
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
2021-05-14 21:17:06 +02:00
|
|
|
// Interface represents an interface to handle json data
|
|
|
|
type Interface interface {
|
2019-06-23 17:22:43 +02:00
|
|
|
Marshal(v interface{}) ([]byte, error)
|
|
|
|
Unmarshal(data []byte, v interface{}) error
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultJSONHandler default json handler
|
2021-05-14 21:17:06 +02:00
|
|
|
DefaultJSONHandler Interface = StdJSON{}
|
2019-06-23 17:22:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// StdJSON implements JSONInterface via encoding/json
|
|
|
|
type StdJSON struct{}
|
|
|
|
|
|
|
|
// Marshal implements JSONInterface
|
|
|
|
func (StdJSON) Marshal(v interface{}) ([]byte, error) {
|
|
|
|
return json.Marshal(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal implements JSONInterface
|
|
|
|
func (StdJSON) Unmarshal(data []byte, v interface{}) error {
|
|
|
|
return json.Unmarshal(data, v)
|
|
|
|
}
|