]> Cypherpunks repositories - gostls13.git/commit
encoding/json: decompose legacy options
authorJoe Tsai <joetsai@digital-static.net>
Tue, 1 Jul 2025 22:39:49 +0000 (15:39 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 14 Jul 2025 15:32:08 +0000 (08:32 -0700)
commit9159cd4ec6b0e9475dc9c71c830035c1c4c13483
tree44083eda6b4373602be42d29c94cb1b7853bdec0
parentc6556b8eb3444b6d5473762ed1082039db7e03b5
encoding/json: decompose legacy options

WARNING: This commit contains breaking changes
for those already using GOEXPERIMENT=jsonv2.

This decomposes FormatBytesWithLegacySemantics as:
* FormatBytesWithLegacySemantics
* FormatByteArrayAsArray
* ParseBytesWithLooseRFC4648

This decomposes FormatTimeWithLegacySemantics as:
* FormatDurationAsNano
* ParseTimeWithLooseRFC3339

In particular, it splits out specific behaviors from the option
that may need to be specified on a finer-grain level.

FormatByteArrayAsArray and FormatDurationAsNano are targeted
to just the default representation of a [N]byte or time.Duration type.
Both of these are not necessary if the `format` tag is explicitly specified.
However, we want to isolate their behavior from other behaviors that used to
be part of FormatBytesWithLegacySemantics and FormatTimeWithLegacySemantics.

ParseBytesWithLooseRFC4648 and ParseTimeWithLooseRFC3339 are targeted
to just historically buggy parsing according to the relevant RFCs,
which may need to be enabled by some services for backwards compatibility.

While FormatTimeWithLegacySemantics is deleted, we still need
FormatBytesWithLegacySemantics to configure highly esoteric
aspects of how v1 used to handle byte slices.

We rename OmitEmptyWithLegacyDefinition as OmitEmptyWithLegacySemantics
to be consistent with other options with the WithLegacySemantics suffix.

Updates #71497

Change-Id: Ic660515fb086fe3af237135f195736de99c2bd33
Reviewed-on: https://go-review.googlesource.com/c/go/+/685395
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
src/encoding/json/internal/jsonflags/flags.go
src/encoding/json/v2/arshal_default.go
src/encoding/json/v2/arshal_test.go
src/encoding/json/v2/arshal_time.go
src/encoding/json/v2_options.go