mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 10:58:18 +08:00
resolve #368 add option to UseNumber() in gin.Context.BindJSON()
This commit is contained in:
parent
df3b79e805
commit
f0c42ad917
@ -10,7 +10,10 @@ import (
|
|||||||
"github.com/json-iterator/go"
|
"github.com/json-iterator/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var (
|
||||||
|
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
EnableDecoderUseNumber = false
|
||||||
|
)
|
||||||
|
|
||||||
type jsonBinding struct{}
|
type jsonBinding struct{}
|
||||||
|
|
||||||
@ -20,6 +23,9 @@ func (jsonBinding) Name() string {
|
|||||||
|
|
||||||
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
|
||||||
decoder := json.NewDecoder(req.Body)
|
decoder := json.NewDecoder(req.Body)
|
||||||
|
if EnableDecoderUseNumber {
|
||||||
|
decoder.UseNumber()
|
||||||
|
}
|
||||||
if err := decoder.Decode(obj); err != nil {
|
if err := decoder.Decode(obj); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user