mirror of
https://gitee.com/dromara/carbon.git
synced 2025-12-06 15:59:30 +08:00
feat(Carbon): 添加空值处理
- 在 UnmarshalJSON 方法中增加空值判断 - 设置 isEmpty 标志以表示空值情况
This commit is contained in:
@@ -55,6 +55,7 @@ func (c Carbon) MarshalJSON() ([]byte, error) {
|
||||
func (c *Carbon) UnmarshalJSON(src []byte) error {
|
||||
v := string(bytes.Trim(src, `"`))
|
||||
if v == "" || v == "null" {
|
||||
c.isEmpty = true
|
||||
return nil
|
||||
}
|
||||
*c = *ParseByLayout(v, DefaultLayout)
|
||||
|
||||
Reference in New Issue
Block a user