Skip to content

Commit

Permalink
Fix Unmarshal error
Browse files Browse the repository at this point in the history
Fix Unmarshal error
  • Loading branch information
gouguoyin committed Nov 4, 2022
2 parents b6fed0b + 512c9a9 commit ac27924
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
22 changes: 11 additions & 11 deletions json.go
Expand Up @@ -113,7 +113,7 @@ func (t *DateTimeMilli) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateTimeMilli{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateTimeMilli struct.
Expand All @@ -135,7 +135,7 @@ func (t *DateTimeMicro) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateTimeMicro{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateTimeMicro struct.
Expand All @@ -157,7 +157,7 @@ func (t *DateTimeNano) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateTimeNano{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateTimeNano struct.
Expand All @@ -179,7 +179,7 @@ func (t *Date) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = Date{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for Date struct.
Expand All @@ -201,7 +201,7 @@ func (t *DateMilli) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateMilli{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateMilli struct.
Expand All @@ -223,7 +223,7 @@ func (t *DateMicro) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateMicro{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateMicro struct.
Expand All @@ -245,7 +245,7 @@ func (t *DateNano) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = DateNano{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for DateNano struct.
Expand All @@ -268,7 +268,7 @@ func (t *Timestamp) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = Timestamp{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for Timestamp struct.
Expand All @@ -291,7 +291,7 @@ func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = TimestampMilli{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for TimestampMilli struct.
Expand All @@ -314,7 +314,7 @@ func (t *TimestampMicro) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = TimestampMicro{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for TimestampMicro struct.
Expand All @@ -337,7 +337,7 @@ func (t *TimestampNano) UnmarshalJSON(b []byte) error {
if c.Error == nil {
*t = TimestampNano{c}
}
return nil
return c.Error
}

// String implements the interface Stringer for TimestampNano struct.
Expand Down
12 changes: 3 additions & 9 deletions json_test.go
Expand Up @@ -45,9 +45,7 @@ func TestCarbon_MarshalJSON(t *testing.T) {
CreatedAt4: TimestampNano{Parse("2025-08-05 13:14:15.999999999")},
}
data, err := json.Marshal(&person)
if err != nil {
assert.NotNil(t, err)
}
assert.Nil(t, err)
fmt.Printf("Person output by json:\n%s\n", data)
}

Expand All @@ -70,9 +68,7 @@ func TestCarbon_UnmarshalJSON(t *testing.T) {
}`

err := json.Unmarshal([]byte(str), &person)
if err != nil {
assert.NotNil(t, err)
}
assert.Nil(t, err)
fmt.Printf("Json string parse to person:\n%+v\n", person)
}

Expand All @@ -94,8 +90,6 @@ func TestError_Json(t *testing.T) {
"created_at4": 0
}`
err := json.Unmarshal([]byte(str), &person)
if err != nil {
assert.NotNil(t, err)
}
assert.NotNil(t, err)
fmt.Printf("Json string parse to person:\n%+v\n", person)
}

0 comments on commit ac27924

Please sign in to comment.