Skip to content

Commit 976948d

Browse files
committed
More cleanup of ExampleBuilder_BodyJSON
1 parent d87154a commit 976948d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

builder_example_test.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ func ExampleBuilder_ToDeserializer() {
650650
}
651651

652652
func ExampleBuilder_BodyJSON() {
653+
// Restore defaults after this test
654+
defaultSerializer := requests.JSONSerializer
655+
defer func() {
656+
requests.JSONSerializer = defaultSerializer
657+
}()
658+
653659
data := struct {
654660
A string `json:"a"`
655661
B int `json:"b"`
@@ -671,16 +677,12 @@ func ExampleBuilder_BodyJSON() {
671677
io.Copy(os.Stdout, req.Body)
672678
fmt.Println()
673679

674-
// Restore default after this test
675-
defaultSerializer := requests.JSONSerializer
676-
defer func() {
677-
requests.JSONSerializer = defaultSerializer
678-
}()
679-
680-
// Have the default JSON serializer indent with two spaces
680+
// Change the default JSON serializer to indent with two spaces
681681
requests.JSONSerializer = func(v any) ([]byte, error) {
682682
return json.MarshalIndent(v, "", " ")
683683
}
684+
685+
// Build a new request using the new indenting serializer
684686
req, err = requests.
685687
New().
686688
BodyJSON(&data).

0 commit comments

Comments
 (0)