| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package json |
||
| 2 | |||
| 3 | import "encoding/json" |
||
| 4 | |||
| 5 | type Helper interface { |
||
| 6 | Marshal(v interface{}) ([]byte, error) |
||
| 7 | Unmarshal(data []byte, v interface{}) error |
||
| 8 | } |
||
| 9 | |||
| 10 | type JSON struct { |
||
| 11 | json Helper |
||
| 12 | } |
||
| 13 | |||
| 14 | func NewJSON(json Helper) *JSON { |
||
| 15 | return &JSON{json: json} |
||
| 16 | } |
||
| 17 | |||
| 18 | func (j *JSON) Marshal(v interface{}) ([]byte, error) { |
||
| 19 | return j.json.Marshal(v) |
||
| 20 | } |
||
| 21 | |||
| 22 | func (j *JSON) Unmarshal(data []byte, v interface{}) error { |
||
| 23 | return j.json.Unmarshal(data, v) |
||
| 24 | } |
||
| 25 | |||
| 26 | type NativeJSON struct{} |
||
| 27 | |||
| 28 | func (n *NativeJSON) Marshal(v interface{}) ([]byte, error) { |
||
| 29 | return json.Marshal(v) |
||
| 30 | } |
||
| 31 | |||
| 32 | func (n *NativeJSON) Unmarshal(data []byte, v interface{}) error { |
||
| 33 | return json.Unmarshal(data, v) |
||
| 34 | } |
||
| 35 |