diff options
Diffstat (limited to 'src/encoding/json/v2/example_test.go')
| -rw-r--r-- | src/encoding/json/v2/example_test.go | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/encoding/json/v2/example_test.go b/src/encoding/json/v2/example_test.go index fe40bff964..c6bf0a864d 100644 --- a/src/encoding/json/v2/example_test.go +++ b/src/encoding/json/v2/example_test.go @@ -402,27 +402,29 @@ func Example_unknownMembers() { // The "format" tag option can be used to alter the formatting of certain types. func Example_formatFlags() { value := struct { - BytesBase64 []byte `json:",format:base64"` - BytesHex [8]byte `json:",format:hex"` - BytesArray []byte `json:",format:array"` - FloatNonFinite float64 `json:",format:nonfinite"` - MapEmitNull map[string]any `json:",format:emitnull"` - SliceEmitNull []any `json:",format:emitnull"` - TimeDateOnly time.Time `json:",format:'2006-01-02'"` - TimeUnixSec time.Time `json:",format:unix"` - DurationSecs time.Duration `json:",format:sec"` - DurationNanos time.Duration `json:",format:nano"` + BytesBase64 []byte `json:",format:base64"` + BytesHex [8]byte `json:",format:hex"` + BytesArray []byte `json:",format:array"` + FloatNonFinite float64 `json:",format:nonfinite"` + MapEmitNull map[string]any `json:",format:emitnull"` + SliceEmitNull []any `json:",format:emitnull"` + TimeDateOnly time.Time `json:",format:'2006-01-02'"` + TimeUnixSec time.Time `json:",format:unix"` + DurationSecs time.Duration `json:",format:sec"` + DurationNanos time.Duration `json:",format:nano"` + DurationISO8601 time.Duration `json:",format:iso8601"` }{ - BytesBase64: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, - BytesHex: [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, - BytesArray: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, - FloatNonFinite: math.NaN(), - MapEmitNull: nil, - SliceEmitNull: nil, - TimeDateOnly: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), - TimeUnixSec: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), - DurationSecs: 12*time.Hour + 34*time.Minute + 56*time.Second + 7*time.Millisecond + 8*time.Microsecond + 9*time.Nanosecond, - DurationNanos: 12*time.Hour + 34*time.Minute + 56*time.Second + 7*time.Millisecond + 8*time.Microsecond + 9*time.Nanosecond, + BytesBase64: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, + BytesHex: [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, + BytesArray: []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, + FloatNonFinite: math.NaN(), + MapEmitNull: nil, + SliceEmitNull: nil, + TimeDateOnly: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), + TimeUnixSec: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), + DurationSecs: 12*time.Hour + 34*time.Minute + 56*time.Second + 7*time.Millisecond + 8*time.Microsecond + 9*time.Nanosecond, + DurationNanos: 12*time.Hour + 34*time.Minute + 56*time.Second + 7*time.Millisecond + 8*time.Microsecond + 9*time.Nanosecond, + DurationISO8601: 12*time.Hour + 34*time.Minute + 56*time.Second + 7*time.Millisecond + 8*time.Microsecond + 9*time.Nanosecond, } b, err := json.Marshal(&value) @@ -452,7 +454,8 @@ func Example_formatFlags() { // "TimeDateOnly": "2000-01-01", // "TimeUnixSec": 946684800, // "DurationSecs": 45296.007008009, - // "DurationNanos": 45296007008009 + // "DurationNanos": 45296007008009, + // "DurationISO8601": "PT12H34M56.007008009S" // } } |
