Commit 976948d 1 parent d87154a commit 976948d Copy full SHA for 976948d
File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -650,6 +650,12 @@ func ExampleBuilder_ToDeserializer() {
650
650
}
651
651
652
652
func ExampleBuilder_BodyJSON () {
653
+ // Restore defaults after this test
654
+ defaultSerializer := requests .JSONSerializer
655
+ defer func () {
656
+ requests .JSONSerializer = defaultSerializer
657
+ }()
658
+
653
659
data := struct {
654
660
A string `json:"a"`
655
661
B int `json:"b"`
@@ -671,16 +677,12 @@ func ExampleBuilder_BodyJSON() {
671
677
io .Copy (os .Stdout , req .Body )
672
678
fmt .Println ()
673
679
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
681
681
requests .JSONSerializer = func (v any ) ([]byte , error ) {
682
682
return json .MarshalIndent (v , "" , " " )
683
683
}
684
+
685
+ // Build a new request using the new indenting serializer
684
686
req , err = requests .
685
687
New ().
686
688
BodyJSON (& data ).
You can’t perform that action at this time.
0 commit comments