xorm/json.go

34 lines
821 B
Go
Raw Normal View History

// 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.
2023-07-31 07:34:44 +00:00
package xorm
2023-07-31 07:34:44 +00:00
import (
stdjson "encoding/json"
)
2023-07-31 07:34:44 +00:00
// JSONHandler represents an interface to handle json data
type JSONHandler interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
var (
// DefaultJSONHandler default json handler
2023-07-31 07:34:44 +00:00
DefaultJSONHandler JSONHandler = StdJSON{}
)
// StdJSON implements JSONInterface via encoding/json
type StdJSON struct{}
// Marshal implements JSONInterface
func (StdJSON) Marshal(v interface{}) ([]byte, error) {
2023-07-31 07:34:44 +00:00
return stdjson.Marshal(v)
}
// Unmarshal implements JSONInterface
func (StdJSON) Unmarshal(data []byte, v interface{}) error {
2023-07-31 07:34:44 +00:00
return stdjson.Unmarshal(data, v)
}