File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -650,6 +650,12 @@ func ExampleBuilder_ToDeserializer() {
650650}
651651
652652func 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 ).
You can’t perform that action at this time.
0 commit comments