Skip to content

Commit 4fb4291

Browse files
authored
Merge pull request #2802 from gautamdsheth/bugfix/2775
Fix #2775: issue with complex JSON payload in REST methods
2 parents ca70f55 + 89c1a16 commit 4fb4291

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6666
- Fixed issue with `Set-PnPContentType` not allowing you to update basic properties of a content type [#2760](https://github.com/pnp/powershell/pull/2760)
6767
- Fixed `Add-PnPField` not supporting a ReturnType to be set for calculated fields when created on the site level [#2765](https://github.com/pnp/powershell/pull/2765)
6868
- Fixed issue with `Invoke-PnPSPRestMethod` throwing error when the response string is empty. [#2784](https://github.com/pnp/powershell/pull/2784)
69+
- Fixed issue with `Invoke-PnPSPRestMethod` and `Invoke-PnPGraphMethod` throwing error when passing complex JSON object as payload.
6970
- Fixed issue with `Add-PnPListItem` and `Set-PnPListItem` not correctly setting the Purview `Unlocked by default`. [#2800](https://github.com/pnp/powershell/pull/2800)
7071

7172
### Contributors

src/Commands/Base/InvokeSPRestMethod.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Net.Http;
1010
using System.Net.Http.Headers;
1111
using System.Text.Json;
12+
using System.Text.Json.Serialization;
1213

1314
namespace PnP.PowerShell.Commands.Admin
1415
{
@@ -92,7 +93,7 @@ protected override void ExecuteCmdlet()
9293
ContentType = "application/json";
9394
}
9495
var contentString = Content is string ? Content.ToString() :
95-
JsonSerializer.Serialize(Content);
96+
JsonSerializer.Serialize(Content, new JsonSerializerOptions() { ReferenceHandler = ReferenceHandler.IgnoreCycles, WriteIndented = true });
9697
request.Content = new StringContent(contentString, System.Text.Encoding.UTF8);
9798
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(ContentType);
9899
}

src/Commands/Graph/InvokeGraphMethod.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Net.Http;
99
using System.Net.Http.Headers;
10+
using System.Text.Json.Serialization;
1011

1112
namespace PnP.PowerShell.Commands.Base
1213
{
@@ -104,7 +105,7 @@ private HttpContent GetHttpContent()
104105
ContentType = "application/json";
105106
}
106107
var contentString = Content is string ? Content.ToString() :
107-
JsonSerializer.Serialize(Content);
108+
JsonSerializer.Serialize(Content, new JsonSerializerOptions() { ReferenceHandler = ReferenceHandler.IgnoreCycles, WriteIndented = true });
108109

109110
HttpContent httpContent = new StringContent(contentString, System.Text.Encoding.UTF8);
110111
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(ContentType);

0 commit comments

Comments
 (0)