Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1132)

Delta Between Two Patch Sets: src/pkg/encoding/json/decode.go

Issue 6759043: code review 6759043: json.Unmarshal: convert nulls to zero values (Closed)
Left Patch Set: Created 11 years, 5 months ago
Right Patch Set: diff -r a2f1842353e7 https://code.google.com/p/go Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/encoding/json/decode_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Represents JSON data structure using native Go types: booleans, floats, 5 // Represents JSON data structure using native Go types: booleans, floats,
6 // strings, arrays, and maps. 6 // strings, arrays, and maps.
7 7
8 package json 8 package json
9 9
10 import ( 10 import (
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 if err != nil { 610 if err != nil {
611 d.error(err) 611 d.error(err)
612 } 612 }
613 return 613 return
614 } 614 }
615 v = pv 615 v = pv
616 616
617 switch c := item[0]; c { 617 switch c := item[0]; c {
618 case 'n': // null 618 case 'n': // null
619 switch v.Kind() { 619 switch v.Kind() {
620 default:
621 d.saveError(&UnmarshalTypeError{"null", v.Type()})
622 case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: 620 case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
623 v.Set(reflect.Zero(v.Type())) 621 v.Set(reflect.Zero(v.Type()))
624 » » } 622 » » » // otherwise, ignore null for primitives/string
625 623 » » }
626 case 't', 'f': // true, false 624 case 't', 'f': // true, false
627 value := c == 't' 625 value := c == 't'
628 switch v.Kind() { 626 switch v.Kind() {
629 default: 627 default:
630 if fromQuoted { 628 if fromQuoted {
631 d.saveError(fmt.Errorf("json: invalid use of ,st ring struct tag, trying to unmarshal %q into %v", item, v.Type())) 629 d.saveError(fmt.Errorf("json: invalid use of ,st ring struct tag, trying to unmarshal %q into %v", item, v.Type()))
632 } else { 630 } else {
633 d.saveError(&UnmarshalTypeError{"bool", v.Type() }) 631 d.saveError(&UnmarshalTypeError{"bool", v.Type() })
634 } 632 }
635 case reflect.Bool: 633 case reflect.Bool:
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 979
982 // Coerce to well-formed UTF-8. 980 // Coerce to well-formed UTF-8.
983 default: 981 default:
984 rr, size := utf8.DecodeRune(s[r:]) 982 rr, size := utf8.DecodeRune(s[r:])
985 r += size 983 r += size
986 w += utf8.EncodeRune(b[w:], rr) 984 w += utf8.EncodeRune(b[w:], rr)
987 } 985 }
988 } 986 }
989 return b[0:w], true 987 return b[0:w], true
990 } 988 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b