cc @adonovan @prattmic
The proposal to introduce encoding.TextAppender (#62384) proposed it with the intention that it would be used instead of MarshalText to avoid unnecessary allocations. It seems clear from the discussions that it was intended to be used by encoding/json/v2 as an optimization instead of using MarshalText. But unfortunately we didn't do that when Go 1.24 was released, so users have started adding the TextAppender interface, expecting that it wouldn't be called by encoding/json. If we had started using it in json when 1.24 was released it would have been better because we had done the work to check that the interface wasn't in use in open source code.
Currently on tip, marshaling JSON for a type implementing TextAppender can result in a different output than in 1.26. That seems like an unnecessarily breaking change and there is a package we've found, github.com/open-policy-agent/opa/v1/ast that depends on the behavior of the json package not using TextAppender.
I think we should reconsider having the encoding/json v1 compatibility mode from using TextAppender to avoid breaking compatibility.
cc @adonovan @prattmic
The proposal to introduce encoding.TextAppender (#62384) proposed it with the intention that it would be used instead of MarshalText to avoid unnecessary allocations. It seems clear from the discussions that it was intended to be used by encoding/json/v2 as an optimization instead of using MarshalText. But unfortunately we didn't do that when Go 1.24 was released, so users have started adding the TextAppender interface, expecting that it wouldn't be called by encoding/json. If we had started using it in json when 1.24 was released it would have been better because we had done the work to check that the interface wasn't in use in open source code.
Currently on tip, marshaling JSON for a type implementing TextAppender can result in a different output than in 1.26. That seems like an unnecessarily breaking change and there is a package we've found, github.com/open-policy-agent/opa/v1/ast that depends on the behavior of the json package not using TextAppender.
I think we should reconsider having the encoding/json v1 compatibility mode from using TextAppender to avoid breaking compatibility.