Seems the expected result should be "{}" because the field createat is empty with ZERO value.
What did you see instead?
The above code will output:
{"createat":"0001-01-01T00:00:00Z"}
The text was updated successfully, but these errors were encountered:
thinkhy
changed the title
How to omit empty value with type time.Time when encoding struct to json payload?
encoding/json: can't omit empty value with type time.Time while encoding struct to json payload?
May 17, 2016
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6 darwin/amd64
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/thinkhy/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.6/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.6/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Seems the expected result should be "{}" because the field createat is empty with ZERO value.
The above code will output:
The text was updated successfully, but these errors were encountered: