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

Why does null.Time text-marshaling return null string? #47

Closed
limoli opened this issue Jul 23, 2019 · 3 comments
Closed

Why does null.Time text-marshaling return null string? #47

limoli opened this issue Jul 23, 2019 · 3 comments

Comments

@limoli
Copy link

limoli commented Jul 23, 2019

Testing my models on GraphQL, I detected some issues regarding text-marshaling implementation in this library.

null.Time returns "null"

func (t Time) MarshalText() ([]byte, error) {
	if !t.Valid {
		return []byte("null"), nil
	}
	return t.Time.MarshalText()
}

Other null.X implementations

// MarshalText implements encoding.TextMarshaler.
// It will encode a blank string when this String is null.
func (s String) MarshalText() ([]byte, error) {
	if !s.Valid {
		return []byte{}, nil
	}
	return []byte(s.String), nil
}

// MarshalText implements encoding.TextMarshaler.
// It will encode a blank string if this Int is null.
func (i Int) MarshalText() ([]byte, error) {
	if !i.Valid {
		return []byte{}, nil
	}
	return []byte(strconv.FormatInt(i.Int64, 10)), nil
}

My question/curiosity is: why does null.Time text-marshaling return a "null" string instead of an empty string like the others?

@guregu
Copy link
Owner

guregu commented Jul 23, 2019

Good question...
I don't have a real answer.
I should probably release v4 and fix this.

Edit: I said it was through a PR but it's totally my fault.

@limoli
Copy link
Author

limoli commented Jul 23, 2019

Thank you so much @guregu ! :)

@guregu
Copy link
Owner

guregu commented Apr 25, 2020

This is fixed in v4.0.0, just released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant