-
Notifications
You must be signed in to change notification settings - Fork 52
marshaling byte slice ignores json.Marshaler/encoding.TextMarshaler interfaces #16
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
Comments
Thanks for raising the issue! I could be wrong, but I don't think the issue comes from the comparison to I'm going to look into it, it should be an easy fix. |
@achille-roussel What I meant was the comparison to |
Yes but in this case we wouldn't enter this code path at all, which means we'll fallback to checking whether the type implements the interfaces below. |
@achille-roussel You are right, I confused named byte slice type and byte slice type regarding the code part I mentionned as the source of the error. |
No worries. It was an edge case because we have tests that verified this behavior already, but it turned out the zero-value of slice types implementing |
Perhaps |
The fix was a bit more subtle than I anticipated actually: the issue you reported was just the fact that we were mistakenly encoding zero-value slices as This is kind of crazy, and I hope no code out there relies on this behavior... anyways, it should be fixed in #17 |
@achille-roussel Ahaha, I know right. This was a pain to implement for me as well. Line 656 in bc545e9
|
I added a test for that case as well, it seems like we're handling it fine 👍 |
When a codec is created for a byte-slice type at
encoding/json/codec.go
Line 80 in bc545e9
it ignores the fact that the type could be implementing the
json.Marshaler
orencoding.TextMarshaler
interfaces. This should be considered in priority, to be compliant with the standard library.The following playground demonstrates the issue:
https://play.golang.org/p/Bm0d3jsWkZf
The relevant code can be found in the standard library at https://github.com/golang/go/blob/da4d58587e0e4028ea384580053c3c455127e446/src/encoding/json/encode.go#L415
The function
newTypeEncoder
checks in priority if thereflect.Value
implements one of the interfaces.The text was updated successfully, but these errors were encountered: