mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: fix UnmarshalTypeError without field and struct values
Fixes #26444
Fixes #27275
Change-Id: I9e8cbff79f7643ca8964c572c1a98172b6831730
GitHub-Last-Rev: 7eea2158b6
GitHub-Pull-Request: golang/go#26719
Reviewed-on: https://go-review.googlesource.com/126897
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
422151ad50
commit
21e85c293d
2 changed files with 20 additions and 3 deletions
|
|
@ -670,6 +670,7 @@ func (d *decodeState) object(v reflect.Value) error {
|
|||
}
|
||||
|
||||
var mapElem reflect.Value
|
||||
originalErrorContext := d.errorContext
|
||||
|
||||
for {
|
||||
// Read opening " of string key or closing }.
|
||||
|
|
@ -829,8 +830,7 @@ func (d *decodeState) object(v reflect.Value) error {
|
|||
return errPhase
|
||||
}
|
||||
|
||||
d.errorContext.Struct = nil
|
||||
d.errorContext.Field = ""
|
||||
d.errorContext = originalErrorContext
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -988,7 +988,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
|
|||
if fromQuoted {
|
||||
return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())
|
||||
}
|
||||
return &UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())}
|
||||
d.saveError(&UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())})
|
||||
case reflect.Interface:
|
||||
n, err := d.convertNumber(s)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue