Skip to content

Commit ab41add

Browse files
committed
- change from "heednull" to "nonil"
1 parent 40e395c commit ab41add

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/encoding/json/encode.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ import (
7171
// false, 0, a nil pointer, a nil interface value, and any empty array,
7272
// slice, map, or string.
7373
//
74-
// The "heednull" option specifies that if the field is a slice or map
74+
// The "nonil" option specifies that if the field is a slice or map
7575
// of nil value, then the value encoded will be [] or {} respectively (instead
76-
// of "null"). If both "heednull" and "omitempty" are present, then "heednull" is
77-
// ignored. If the field is not a slice or map, "heednull" does nothing.
76+
// of "null"). If both "nonil" and "omitempty" are present, then "nonil" is
77+
// ignored. If the field is not a slice or map, "nonil" does nothing.
7878
//
7979
// As a special case, if the field tag is "-", the field is always omitted.
8080
// Note that a field with name "-" can still be generated using the tag "-,".
@@ -662,7 +662,7 @@ FieldLoop:
662662
}
663663
opts.quoted = f.quoted
664664

665-
if f.heedNull {
665+
if f.noNil {
666666
if f.typ.Kind() == reflect.Slice && fv.IsNil() {
667667
e.WriteString("[]")
668668
} else if f.typ.Kind() == reflect.Map && fv.IsNil() {
@@ -1055,7 +1055,7 @@ type field struct {
10551055
index []int
10561056
typ reflect.Type
10571057
omitEmpty bool
1058-
heedNull bool
1058+
noNil bool
10591059
quoted bool
10601060

10611061
encoder encoderFunc
@@ -1173,7 +1173,7 @@ func typeFields(t reflect.Type) []field {
11731173
index: index,
11741174
typ: ft,
11751175
omitEmpty: opts.Contains("omitempty"),
1176-
heedNull: !opts.Contains("omitempty") && opts.Contains("heednull"),
1176+
noNil: !opts.Contains("omitempty") && opts.Contains("nonil"),
11771177
quoted: quoted,
11781178
}
11791179
field.nameBytes = []byte(field.name)

src/encoding/json/encode_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ type Optionals struct {
4242
Str struct{} `json:"str"`
4343
Sto struct{} `json:"sto,omitempty"`
4444

45-
Slh []string `json:"slh,heednull"`
46-
Slb []string `json:"slb,omitempty,heednull"`
45+
Slh []string `json:"slh,nonil"`
46+
Slb []string `json:"slb,omitempty,nonil"`
4747

48-
Mh map[string]interface{} `json:"mh,heednull"`
49-
Mb map[string]interface{} `json:"mb,omitempty,heednull"`
48+
Mh map[string]interface{} `json:"mh,nonil"`
49+
Mb map[string]interface{} `json:"mb,omitempty,nonil"`
5050
}
5151

5252
var optionalsExpected = `{

0 commit comments

Comments
 (0)