Skip to content

encoding/json: consider implications of using TextAppender in V1 backwards-compatibility mode #79852

Description

@matloob

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.okay-after-rc2Used by release team to mark a release-blocker issue as okay to resolve either before or after rc2release-blocker

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions