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

Use encoding TextMarshaler & TextUnmarshaler instead of JSON equivalents #95

Merged
merged 1 commit into from May 18, 2022

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented May 18, 2022

Technically quoted string is valid JSON, but in the context of go-version we deal with single line of text being serialized or unserialized, not structures which are more common for JSON or YAML.

Implementing encoding.TextMarshaler and encoding.TextUnmarshaler retains the same functionality (as demonstrated by existing passing tests) since json.Marshal and json.Unmarshal will both reflect that interface and makes it work for other formats, such as YAML.

cc @jukie

v.si = temp.si
v.original = temp.original

*v = *temp
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to just copy the whole content of the struct without having to explicitly list out all fields.

@radeksimko radeksimko requested review from shore and mdeggies May 18, 2022 07:31
@jukie
Copy link
Contributor

jukie commented May 18, 2022

Interesting, thanks for the cc and explanation!

Copy link
Contributor

@jukie jukie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't affect functionality but shouldn't the tests be renamed as well?

@radeksimko
Copy link
Member Author

Technically the tests are still testing JSON marshaling/unmarshaling, which is probably the most common use case and AFAICT there isn't equivalent of json.Marshal() or json.Unmarshal() for text, so I'd just think of the existing tests as E2E tests - in which case the naming is correct? 🤷🏻‍♂️

@radeksimko radeksimko merged commit 1a9a0e4 into main May 18, 2022
@radeksimko radeksimko deleted the json-2-text-marshaler branch May 18, 2022 16:57
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

Successfully merging this pull request may close these issues.

None yet

3 participants