pki/vendor/xorm.io/xorm/internal/json/json.go

32 lines
796 B
Go
Raw Permalink Normal View History

2020-11-25 20:36:07 +01: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.
package json
import "encoding/json"
2021-08-30 20:04:15 +02:00
// Interface represents an interface to handle json data
type Interface interface {
2020-11-25 20:36:07 +01:00
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
var (
// DefaultJSONHandler default json handler
2021-08-30 20:04:15 +02:00
DefaultJSONHandler Interface = StdJSON{}
2020-11-25 20:36:07 +01: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)
}