Skip to content

Commit

Permalink
Merge pull request #2802 from gautamdsheth/bugfix/2775
Browse files Browse the repository at this point in the history
Fix #2775: issue with complex JSON payload in REST methods
  • Loading branch information
gautamdsheth committed Feb 11, 2023
2 parents ca70f55 + 89c1a16 commit 4fb4291
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed issue with `Set-PnPContentType` not allowing you to update basic properties of a content type [#2760](https://github.com/pnp/powershell/pull/2760)
- 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)
- Fixed issue with `Invoke-PnPSPRestMethod` throwing error when the response string is empty. [#2784](https://github.com/pnp/powershell/pull/2784)
- Fixed issue with `Invoke-PnPSPRestMethod` and `Invoke-PnPGraphMethod` throwing error when passing complex JSON object as payload.
- Fixed issue with `Add-PnPListItem` and `Set-PnPListItem` not correctly setting the Purview `Unlocked by default`. [#2800](https://github.com/pnp/powershell/pull/2800)

### Contributors
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Base/InvokeSPRestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Admin
{
Expand Down Expand Up @@ -92,7 +93,7 @@ protected override void ExecuteCmdlet()
ContentType = "application/json";
}
var contentString = Content is string ? Content.ToString() :
JsonSerializer.Serialize(Content);
JsonSerializer.Serialize(Content, new JsonSerializerOptions() { ReferenceHandler = ReferenceHandler.IgnoreCycles, WriteIndented = true });
request.Content = new StringContent(contentString, System.Text.Encoding.UTF8);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(ContentType);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Graph/InvokeGraphMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Base
{
Expand Down Expand Up @@ -104,7 +105,7 @@ private HttpContent GetHttpContent()
ContentType = "application/json";
}
var contentString = Content is string ? Content.ToString() :
JsonSerializer.Serialize(Content);
JsonSerializer.Serialize(Content, new JsonSerializerOptions() { ReferenceHandler = ReferenceHandler.IgnoreCycles, WriteIndented = true });

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

0 comments on commit 4fb4291

Please sign in to comment.