mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 09:40:24 +08:00
40 lines
982 B
Go
40 lines
982 B
Go
package mapping
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/tal-tech/go-zero/core/jsonx"
|
|
)
|
|
|
|
const jsonTagKey = "json"
|
|
|
|
var jsonUnmarshaler = NewUnmarshaler(jsonTagKey)
|
|
|
|
// UnmarshalJsonBytes unmarshals content into v.
|
|
func UnmarshalJsonBytes(content []byte, v interface{}) error {
|
|
return unmarshalJsonBytes(content, v, jsonUnmarshaler)
|
|
}
|
|
|
|
// UnmarshalJsonReader unmarshals content from reader into v.
|
|
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)
|
|
}
|