Skip to content

Commit 3e48e5f

Browse files
committed
update readme: add omitzero info
1 parent 25a9e71 commit 3e48e5f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
null is a library with reasonable options for dealing with nullable SQL and JSON values
55

6-
There are two packages: `null` and its subpackage `zero`.
6+
There are two packages: `null` and its subpackage `zero`.
77

88
Types in `null` will only be considered null on null input, and will JSON encode to `null`. If you need zero and null be considered separate values, use these.
99

@@ -14,6 +14,7 @@ Types in `zero` are treated like zero values in Go: blank string input will prod
1414
- All types implement `sql.Scanner` and `driver.Valuer`, so you can use this library in place of `sql.NullXXX`.
1515
- All types also implement `json.Marshaler` and `json.Unmarshaler`, so you can marshal them to their native JSON representation.
1616
- All non-generic types implement `encoding.TextMarshaler`, `encoding.TextUnmarshaler`. A null object's `MarshalText` will return a blank string.
17+
- All types implement `interface { IsZero() bool }`. Combined with Go 1.24's `,omitzero`, this lets you omit null types from JSON.
1718

1819
## null package
1920

@@ -25,17 +26,17 @@ Nullable string.
2526
Marshals to JSON null if SQL source data is null. Zero (blank) input will not produce a null String.
2627

2728
#### null.Int, null.Int32, null.Int16, null.Byte
28-
Nullable int64/int32/int16/byte.
29+
Nullable int64/int32/int16/byte.
2930

3031
Marshals to JSON null if SQL source data is null. Zero input will not produce a null Int.
3132

3233
#### null.Float
33-
Nullable float64.
34+
Nullable float64.
3435

3536
Marshals to JSON null if SQL source data is null. Zero input will not produce a null Float.
3637

3738
#### null.Bool
38-
Nullable bool.
39+
Nullable bool.
3940

4041
Marshals to JSON null if SQL source data is null. False input will not produce a null Bool.
4142

@@ -58,14 +59,14 @@ Nullable string.
5859
Will marshal to a blank string if null. Blank string input produces a null String. Null values and zero values are considered equivalent.
5960

6061
#### zero.Int, zero.Int32, zero.Int16, zero.Byte
61-
Nullable int64/int32/int16/byte.
62+
Nullable int64/int32/int16/byte.
6263

63-
Will marshal to 0 if null. 0 produces a null Int. Null values and zero values are considered equivalent.
64+
Will marshal to 0 if null. 0 produces a null Int. Null values and zero values are considered equivalent.
6465

6566
#### zero.Float
6667
Nullable float64.
6768

68-
Will marshal to 0.0 if null. 0.0 produces a null Float. Null values and zero values are considered equivalent.
69+
Will marshal to 0.0 if null. 0.0 produces a null Float. Null values and zero values are considered equivalent.
6970

7071
#### zero.Bool
7172
Nullable bool.
@@ -104,7 +105,8 @@ This package isn't intended to be a catch-all data-wrangling package. It is esse
104105
- Unmarshaling from JSON `sql.NullXXX` JSON objects (e.g. `{"Int64": 123, "Valid": true}`) is no longer supported. It's unlikely many people used this, but if you need it, use v3.
105106

106107
### Bugs
107-
`json`'s `",omitempty"` struct tag does not work correctly right now. It will never omit a null or empty String. This might be [fixed eventually](https://github.com/golang/go/issues/11939).
108+
- ~~`json`'s `",omitempty"` struct tag does not work correctly right now. It will never omit a null or empty String. This might be [fixed eventually](https://github.com/golang/go/issues/11939).~~
109+
- As of Go 1.24, you can use `,omitzero` to omit this package's types. Only took 10 years!
108110

109111
### License
110112
BSD

0 commit comments

Comments
 (0)