The issue is that MarshalJSON is defined as a method on the pointer version of the integer. It should probably be the value receiver. Closing as duplicate of #22967
Also note that elements in maps aren't addressable so any typical automatic T to *T receiver switch sugar doesn't happen since the map element can't have its pointer addr taken.
In the case where you had a class type with a union property, and that
class type was the value type of a map, the union wouldn't use the
custom unmarshaller, because of complicated Go stuff:
golang/go#23263 (comment)
This behavior is counterintuitive and requires bookkeeping to figure out which types are in a value context under which circumstances.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/HuQg9qdj4HE
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: