match behavior of encoding/json when unmarshaling into an array

excess elements are ignored silently
This commit is contained in:
Nicolas S. Dade
2016-09-23 16:53:34 -07:00
parent 0f22c066ac
commit 32cc087149
+7 -3
View File
@@ -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(']')")