googleapis / google-api-go-client

Auto-generated Google APIs for Go.
https://pkg.go.dev/google.golang.org/api
BSD 3-Clause "New" or "Revised" License
3.9k stars 1.11k forks source link

fix: allow ForceSendFields to work for map types #2670

Closed codyoss closed 4 days ago

codyoss commented 1 week ago

The way we generate map types today is map[string]T, where T is a non-pointer type. This means the pointer receiver version of MarshalJSON does not fulfill the Marshaler interface. This is turn means that MarshalJSON is not called in these cases so ForceSendFields overrides do not work. To fix this we can switch the impl to a value receiver which fulfills both value and pointer types. This is not a breaking change for the API, but there is a slight behaviour change if someone was calling MarshalJSON directly. Nil *T's that call MarshalJSON directly will now panic instead of returning JSON null. This seems like unlikely usage and worth breaking to fix a bug in common usage.

Internal Bug: 349580049

diviner524 commented 1 week ago

This means the value receiver version of MarshalJSON does not fulfill the Marshaler interface.

nit: The description looks to be a bit misleading. I think you mean the pointer receiver version of MarshalJSON.

diviner524 commented 1 week ago

/lgtm

Thanks for the quick fix!