From 32cc087149a528b13873298390487677f7522bd0 Mon Sep 17 00:00:00 2001 From: "Nicolas S. Dade" Date: Fri, 23 Sep 2016 16:53:34 -0700 Subject: [PATCH] match behavior of encoding/json when unmarshaling into an array excess elements are ignored silently --- gen/decoder.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gen/decoder.go b/gen/decoder.go index 21fea2f..0688e5d 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -143,11 +143,15 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field fmt.Fprintln(g.out, ws+"} else {") fmt.Fprintln(g.out, ws+" in.Delim('[')") fmt.Fprintln(g.out, ws+" "+iterVar+" := 0") - fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') && "+iterVar+" < "+fmt.Sprint(length)+" {") + fmt.Fprintln(g.out, ws+" for !in.IsDelim(']') {") + fmt.Fprintln(g.out, ws+" if "+iterVar+" < "+fmt.Sprint(length)+" {") - g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+2) + g.genTypeDecoder(elem, out+"["+iterVar+"]", tags, indent+3) - fmt.Fprintln(g.out, ws+" "+iterVar+"++") + fmt.Fprintln(g.out, ws+" "+iterVar+"++") + fmt.Fprintln(g.out, ws+" } else {") + fmt.Fprintln(g.out, ws+" in.SkipRecursive()") + fmt.Fprintln(g.out, ws+" }") fmt.Fprintln(g.out, ws+" in.WantComma()") fmt.Fprintln(g.out, ws+" }") fmt.Fprintln(g.out, ws+" in.Delim(']')")