mirror of https://github.com/goccy/go-json.git
Fix stream decoding with error
This commit is contained in:
parent
a89c9e30df
commit
8f8d2d8cea
|
@ -200,6 +200,7 @@ func (d *Decoder) DecodeWithOption(v interface{}, optFuncs ...DecodeOptionFunc)
|
||||||
optFunc(s.Option)
|
optFunc(s.Option)
|
||||||
}
|
}
|
||||||
if err := dec.DecodeStream(s, 0, header.ptr); err != nil {
|
if err := dec.DecodeStream(s, 0, header.ptr); err != nil {
|
||||||
|
d.s.SkipErrorValue()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Reset()
|
s.Reset()
|
||||||
|
|
|
@ -3776,3 +3776,18 @@ func TestIssue282(t *testing.T) {
|
||||||
t.Fatalf("failed to assign map value")
|
t.Fatalf("failed to assign map value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeStreamWithError(t *testing.T) {
|
||||||
|
type Test struct {
|
||||||
|
Val int `json:"val"`
|
||||||
|
}
|
||||||
|
p := Test{}
|
||||||
|
dec := json.NewDecoder(strings.NewReader("[12,{\"val\" : 2}]"))
|
||||||
|
dec.Token()
|
||||||
|
for dec.More() {
|
||||||
|
_ = dec.Decode(&p) // ignore error value
|
||||||
|
}
|
||||||
|
if p.Val != 2 {
|
||||||
|
t.Fatal("failed to decode")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -369,6 +369,10 @@ func (s *Stream) skipArray(depth int64) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Stream) SkipErrorValue() {
|
||||||
|
_ = s.skipValue(0)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Stream) skipValue(depth int64) error {
|
func (s *Stream) skipValue(depth int64) error {
|
||||||
_, cursor, p := s.stat()
|
_, cursor, p := s.stat()
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in New Issue