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

⚠️ Add support for encoding.TextMarshaler #1015

Merged
merged 2 commits into from
Nov 17, 2024

Conversation

twz123
Copy link
Contributor

@twz123 twz123 commented Jul 30, 2024

Whenever a type is encountered that implements encoding.TextMarshaler but not encoding/json.Marshaler, assume that it will be encoded as a string.

This is a breaking change, as types that implement TextMarshaler are now handled differently. On the other hand, this probably restores reality for all but the most customized setups, as Go's JSON package will also check for the presence of this interface, and output a JSON string.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 30, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @twz123. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 30, 2024
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/ok-to-test

Thanks for your contribution, the change makes sense. One comment re testing

// URL4 is an alias of [net/url.URL]. It implements [encoding.TextMarshaler] so
// that it can be used in K8s CRDs such that the CRD resource will have the URL
// but operator code can can work with the URL struct.
type URL4 url.URL
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand the difference between the two, could you explain why they both exist?

What seems to be missing as a testcase is something that implements both json marshaller and text marshaller, in that case the json marshalling must take precedence

Copy link
Contributor Author

@twz123 twz123 Nov 12, 2024

Choose a reason for hiding this comment

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

I do not understand the difference between the two, could you explain why they both exist?

It's been a while since I wrote that piece of code. Need to figure out myself 🙃

What seems to be missing as a testcase is something that implements both json marshaller and text marshaller, in that case the json marshalling must take precedence

Will do a rebase and add the test in the next few days I hope.

Copy link
Contributor Author

@twz123 twz123 Nov 15, 2024

Choose a reason for hiding this comment

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

I do not understand the difference between the two, could you explain why they both exist?

You mean URL3 and URL4? I mimicked the URL and URL2 types. One is a regular struct, the other is a newtype. I guess it makes sense to have both, as they might behave differently when using reflection?

What seems to be missing as a testcase is something that implements both json marshaller and text marshaller, in that case the json marshalling must take precedence

Added.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 10, 2024
Whenever a type is encountered that implements encoding.TextMarshaler
but not encoding/json.Marshaler, assume that it will be encoded as
a string.

This is a breaking change, as types that implement TextMarshaler are now
handled differently. On the other hand, this probably restores reality
for all but the most customized setups, as Go's JSON package will also
check for the presence of this interface, and output a JSON string.

Signed-off-by: Tom Wieczorek <[email protected]>
Test that json.Marshaler has precedence over encoding.TextMarshaler.

Signed-off-by: Tom Wieczorek <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 15, 2024
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 17, 2024
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 17, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 601d830a18f14ade1eee173d2ecf80e4af823d80

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, twz123

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 17, 2024
@k8s-ci-robot k8s-ci-robot merged commit e92e85d into kubernetes-sigs:main Nov 17, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants