Skip to content

Commit

Permalink
More cleanup of ExampleBuilder_BodyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Oct 6, 2023
1 parent d87154a commit 976948d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions builder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ func ExampleBuilder_ToDeserializer() {
}

func ExampleBuilder_BodyJSON() {
// Restore defaults after this test
defaultSerializer := requests.JSONSerializer
defer func() {
requests.JSONSerializer = defaultSerializer
}()

data := struct {
A string `json:"a"`
B int `json:"b"`
Expand All @@ -671,16 +677,12 @@ func ExampleBuilder_BodyJSON() {
io.Copy(os.Stdout, req.Body)
fmt.Println()

// Restore default after this test
defaultSerializer := requests.JSONSerializer
defer func() {
requests.JSONSerializer = defaultSerializer
}()

// Have the default JSON serializer indent with two spaces
// Change the default JSON serializer to indent with two spaces
requests.JSONSerializer = func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}

// Build a new request using the new indenting serializer
req, err = requests.
New().
BodyJSON(&data).
Expand Down

0 comments on commit 976948d

Please sign in to comment.