json.*NativeJSON.Unmarshal   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package json
2
3
import "encoding/json"
4
5
// Helper is an interface for JSON helper.
6
type Helper interface {
7
	Marshal(v interface{}) ([]byte, error)
8
	Unmarshal(data []byte, v interface{}) error
9
}
10
11
// JSON is a wrapper for JSON helper.
12
type JSON struct {
13
	json Helper
14
}
15
16
// NewJSON returns a new JSON.
17
func NewJSON(json Helper) *JSON {
18
	return &JSON{json: json}
19
}
20
21
// Marshal marshals the given value to JSON.
22
func (j *JSON) Marshal(v interface{}) ([]byte, error) {
23
	return j.json.Marshal(v)
24
}
25
26
// Unmarshal unmarshals the given JSON to the given value.
27
func (j *JSON) Unmarshal(data []byte, v interface{}) error {
28
	return j.json.Unmarshal(data, v)
29
}
30
31
// NativeJSON is a wrapper for encoding/json.
32
type NativeJSON struct{}
33
34
// Marshal marshals the given value to JSON.
35
func (*NativeJSON) Marshal(v interface{}) ([]byte, error) {
36
	return json.Marshal(v)
37
}
38
39
// Unmarshal unmarshals the given JSON to the given value.
40
func (*NativeJSON) Unmarshal(data []byte, v interface{}) error {
41
	return json.Unmarshal(data, v)
42
}
43