1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

Start Migration from Newtonsoft.Json to System.Text.Json (#1803)

* Start switch to System.Text.Json

* Work on switching to System.Text.Json

* Main work on STJ refactor

* Fix build errors

* Run formatting

* Delete unused file

* Use legacy for two factor providers

* Run formatter

* Add TokenProviderTests

* Run formatting

* Fix merge issues

* Switch to use JsonSerializer

* Address PR feedback

* Fix formatting

* Ran formatter

* Switch to async

* Ensure Enums are serialized as strings

* Fix formatting

* Enqueue single items as arrays

* Remove CreateAsync method on AzureQueueService
This commit is contained in:
Justin Baur
2022-01-21 09:36:25 -05:00
committed by GitHub
parent 897a76ff48
commit 5268f2781e
91 changed files with 974 additions and 698 deletions

View File

@ -1,13 +1,13 @@
using System;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace Bit.Billing.Controllers
{
@ -53,7 +53,7 @@ namespace Bit.Billing.Controllers
try
{
var json = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(body), Formatting.Indented);
var json = JsonSerializer.Serialize(JsonSerializer.Deserialize<JsonDocument>(body), JsonHelpers.Indented);
_logger.LogInformation(Constants.BypassFiltersEventId, "Apple IAP Notification:\n\n{0}", json);
return new OkResult();
}

View File

@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Bit.Core.Repositories;
using Bit.Core.Settings;
@ -13,7 +14,6 @@ using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
namespace Bit.Billing.Controllers
{
@ -62,23 +62,18 @@ namespace Bit.Billing.Controllers
return new BadRequestResult();
}
string body = null;
using (var reader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8))
{
body = await reader.ReadToEndAsync();
}
if (string.IsNullOrWhiteSpace(body))
using var body = await JsonSerializer.DeserializeAsync<JsonDocument>(HttpContext.Request.Body);
var root = body.RootElement;
if (root.ValueKind != JsonValueKind.Object)
{
return new BadRequestResult();
}
try
{
dynamic data = JsonConvert.DeserializeObject(body);
string ticketId = data.ticket_id;
string ticketContactEmail = data.ticket_contact_email;
string ticketTags = data.ticket_tags;
var ticketId = root.GetProperty("ticket_id").GetString();
var ticketContactEmail = root.GetProperty("ticket_contact_email").GetString();
var ticketTags = root.GetProperty("ticket_tags").GetString();
if (string.IsNullOrWhiteSpace(ticketId) || string.IsNullOrWhiteSpace(ticketContactEmail))
{
return new BadRequestResult();
@ -120,9 +115,11 @@ namespace Bit.Billing.Controllers
updateBody.Add("tags", tagsToUpdate);
}
var updateRequest = new HttpRequestMessage(HttpMethod.Put,
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}", ticketId));
updateRequest.Content = new StringContent(JsonConvert.SerializeObject(updateBody),
Encoding.UTF8, "application/json");
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}", ticketId))
{
Content = JsonContent.Create(updateBody),
};
await CallFreshdeskApiAsync(updateRequest);
@ -132,9 +129,10 @@ namespace Bit.Billing.Controllers
{ "private", true }
};
var noteRequest = new HttpRequestMessage(HttpMethod.Post,
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}/notes", ticketId));
noteRequest.Content = new StringContent(JsonConvert.SerializeObject(noteBody),
Encoding.UTF8, "application/json");
string.Format("https://bitwarden.freshdesk.com/api/v2/tickets/{0}/notes", ticketId))
{
Content = JsonContent.Create(noteBody),
};
await CallFreshdeskApiAsync(noteRequest);
}