Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2775: issue with complex JSON payload in REST methods #2802

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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