Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unmarshal error #161

Merged
merged 1 commit into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}