dromara / carbon

A simple, semantic and developer-friendly golang package for time.
https://pkg.go.dev/github.com/dromara/carbon/v2
MIT License
4.83k stars 242 forks source link

json null value #240

Closed a8ss closed 1 month ago

a8ss commented 4 months ago

Hello,

I encountered an issue with the following code:

c := struct {
    ActiveTime carbon.TimestampMilli `json:"activeTimeStamp"`
}{}

err := json.Unmarshal([]byte(`{"activeTimeStamp":null}`), &c)
fmt.Println(c.ActiveTime, c.ActiveTime.IsValid(), c.ActiveTime.IsZero(), err)

golang version: such as 1.21

carbon version: such as 2.3.12

I expected to get:

0 false true <nill>

But I actually get:

0 true false <nil>

Thanks!

gouguoyin commented 1 month ago

v2.4.1 has been fixed and released https://github.com/golang-module/carbon/blob/e3a062b142b3b57c83d06ba3e2079e9e0918a3ea/encoding_unit_test.go#L396