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

encoding/json: incorrect slice marshaling for slice of bytes implementing json.Marshaler #13783

Closed
tarndt opened this issue Dec 30, 2015 · 3 comments

Comments

Projects
None yet
4 participants
@tarndt
Copy link

commented Dec 30, 2015

encoding/json: Incorrect slice marshaling for slice of bytes implementing json.Marshaler:

Steps to reproduce:

  1. Create a type that is based on byte
  2. Implement json.Marshaler
  3. Create a slice of said byte type
  4. Attempt to call json.Marshal on that slice
  5. Observe incorrect result, yourtype.MarshalJSON() is never called.

Repeat with int, works as expected.
Use your original byte type, but put them in a slice of json.Marshaler, works as expected.

Code showing working cases and non-working case side-by-side: http://play.golang.org/p/5xgjl4e04R

System details: go1.5.1 / amd64

@ianlancetaylor ianlancetaylor changed the title encoding/json: Incorrect slice marshaling for slice of bytes implementing json.Marshaler encoding/json: incorrect slice marshaling for slice of bytes implementing json.Marshaler Jan 21, 2016

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Jan 21, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Feb 21, 2016

CL https://golang.org/cl/19725 mentions this issue.

@joeshaw

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2016

Are there any backward compatibility considerations for this? It seems like a legit bug otherwise.

@gopherbot gopherbot closed this in cdc0ebb Apr 6, 2016

@gopherbot

This comment has been minimized.

Copy link

commented May 23, 2016

CL https://golang.org/cl/23294 mentions this issue.

gopherbot pushed a commit that referenced this issue May 24, 2016

encoding/json: additional tests and fixes for []typedByte encoding/de…
…coding

CL 19725 changed the encoding of []typedByte to look for
typedByte.MarshalJSON and typedByte.MarshalText.
Previously it was handled like []byte, producing a base64 encoding of the underlying byte data.

CL 19725 forgot to look for (*typedByte).MarshalJSON and (*typedByte).MarshalText,
as the marshaling of other slices would. Add test and fix for those.

This CL also adds tests that the decoder can handle both the old and new encodings.
(This was true even in Go 1.6, which is the only reason we can consider this
not an incompatible change.)

For #13783.

Change-Id: I7cab8b6c0154a7f2d09335b7fa23173bcf856c37
Reviewed-on: https://go-review.googlesource.com/23294
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>

@golang golang locked and limited conversation to collaborators May 23, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.