forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonunmarshaler.go
37 lines (27 loc) · 873 Bytes
/
jsonunmarshaler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package mapping
import (
"io"
"github.com/wjames2000/go-zero/core/jsonx"
)
const jsonTagKey = "json"
var jsonUnmarshaler = NewUnmarshaler(jsonTagKey)
func UnmarshalJsonBytes(content []byte, v interface{}) error {
return unmarshalJsonBytes(content, v, jsonUnmarshaler)
}
func UnmarshalJsonReader(reader io.Reader, v interface{}) error {
return unmarshalJsonReader(reader, v, jsonUnmarshaler)
}
func unmarshalJsonBytes(content []byte, v interface{}, unmarshaler *Unmarshaler) error {
var m map[string]interface{}
if err := jsonx.Unmarshal(content, &m); err != nil {
return err
}
return unmarshaler.Unmarshal(m, v)
}
func unmarshalJsonReader(reader io.Reader, v interface{}, unmarshaler *Unmarshaler) error {
var m map[string]interface{}
if err := jsonx.UnmarshalFromReader(reader, &m); err != nil {
return err
}
return unmarshaler.Unmarshal(m, v)
}