]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: improve Decode example
authorQuentin Smith <quentin@golang.org>
Thu, 26 May 2016 21:53:21 +0000 (17:53 -0400)
committerQuentin Smith <quentin@golang.org>
Thu, 26 May 2016 22:40:14 +0000 (22:40 +0000)
Decoding a JSON message does not touch unspecified or null fields;
always use a new underlying struct to prevent old field values from
sticking around.

Fixes: #14640
Change-Id: Ica78c208ce104e2cdee1d4e92bf58596ea5587c8
Reviewed-on: https://go-review.googlesource.com/23483
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/encoding/json/example_test.go

index 326bdc9540ef9b71466bf06723b3bcb89963835e..555eff93c0ec38576b7f9d4d1e8772b6aec7ef60 100644 (file)
@@ -143,10 +143,9 @@ func ExampleDecoder_Decode_stream() {
        }
        fmt.Printf("%T: %v\n", t, t)
 
-       var m Message
        // while the array contains values
        for dec.More() {
-
+               var m Message
                // decode an array value (Message)
                err := dec.Decode(&m)
                if err != nil {