| 1 |
// Copyright (c) 2026, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
//go:build go1.27 |
| 8 |
// +build go1.27 |
| 9 |
|
| 10 |
package td |
| 11 |
|
| 12 |
import ( |
| 13 |
jsonv1 "encoding/json" |
| 14 |
"encoding/json/v2" |
| 15 |
) |
| 16 |
|
| 17 |
type jsonv2Options = json.Options |
| 18 |
|
| 19 |
func joinOptions(a, b jsonv2Options) jsonv2Options { |
| 20 |
return json.JoinOptions(a, b) |
| 21 |
} |
| 22 |
|
| 23 |
func jsonMarshal(v any, opts jsonv2Options) ([]byte, error) { |
| 24 |
if opts == nil { |
| 25 |
opts = jsonv1.DefaultOptionsV1() |
| 26 |
} |
| 27 |
return json.Marshal(v, opts) |
| 28 |
} |
| 29 |
|
| 30 |
func jsonUnmarshal(data []byte, v any, opts jsonv2Options) error { |
| 31 |
if opts == nil { |
| 32 |
opts = jsonv1.DefaultOptionsV1() |
| 33 |
} |
| 34 |
return json.Unmarshal(data, v, opts) |
| 35 |
} |