google-api-go-client icon indicating copy to clipboard operation
google-api-go-client copied to clipboard

fix: allow ForceSendFields to work for map types

Open codyoss opened this issue 1 year ago • 2 comments

The way we generate map types today is map[string]T, where T is a non-pointer type. This means the value 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

codyoss avatar Jul 03 '24 18:07 codyoss

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 avatar Jul 03 '24 22:07 diviner524

/lgtm

Thanks for the quick fix!

diviner524 avatar Jul 03 '24 22:07 diviner524