Skip to content

Commit 1d15407

Browse files
committed
refactor: use JsonSerializer of System.Text.Json
1 parent 29cf3c2 commit 1d15407

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/IdentityServer4/test/IdentityServer.IntegrationTests/Endpoints/Authorize/JwtRequestAuthorizeTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
using IdentityServer4.Test;
1313
using Microsoft.IdentityModel.Logging;
1414
using Microsoft.IdentityModel.Tokens;
15-
using Newtonsoft.Json;
1615
using System;
1716
using System.Collections.Generic;
1817
using System.IdentityModel.Tokens.Jwt;
1918
using System.Net.Http;
2019
using System.Net.Http.Headers;
2120
using System.Security.Claims;
2221
using System.Security.Cryptography.X509Certificates;
22+
using System.Text.Json;
2323
using System.Threading.Tasks;
2424
using Xunit;
2525

@@ -70,13 +70,13 @@ public JwtRequestAuthorizeTests()
7070
{
7171
// RSA key as JWK
7272
Type = IdentityServerConstants.SecretTypes.JsonWebKey,
73-
Value = JsonConvert.SerializeObject(JsonWebKeyConverter.ConvertFromRSASecurityKey(_rsaKey))
73+
Value = JsonSerializer.Serialize(JsonWebKeyConverter.ConvertFromRSASecurityKey(_rsaKey))
7474
},
7575
new Secret
7676
{
7777
// x509 cert as JWK
7878
Type = IdentityServerConstants.SecretTypes.JsonWebKey,
79-
Value = JsonConvert.SerializeObject(JsonWebKeyConverter.ConvertFromX509SecurityKey(new X509SecurityKey(TestCert.Load())))
79+
Value = JsonSerializer.Serialize(JsonWebKeyConverter.ConvertFromX509SecurityKey(new X509SecurityKey(TestCert.Load())))
8080
}
8181
},
8282

@@ -114,13 +114,13 @@ public JwtRequestAuthorizeTests()
114114
{
115115
// RSA key as JWK
116116
Type = IdentityServerConstants.SecretTypes.JsonWebKey,
117-
Value = JsonConvert.SerializeObject(JsonWebKeyConverter.ConvertFromRSASecurityKey(_rsaKey))
117+
Value = JsonSerializer.Serialize(JsonWebKeyConverter.ConvertFromRSASecurityKey(_rsaKey))
118118
},
119119
new Secret
120120
{
121121
// x509 cert as JWK
122122
Type = IdentityServerConstants.SecretTypes.JsonWebKey,
123-
Value = JsonConvert.SerializeObject(JsonWebKeyConverter.ConvertFromX509SecurityKey(new X509SecurityKey(TestCert.Load())))
123+
Value = JsonSerializer.Serialize(JsonWebKeyConverter.ConvertFromX509SecurityKey(new X509SecurityKey(TestCert.Load())))
124124
}
125125
},
126126

@@ -490,9 +490,9 @@ public async Task mismatch_in_jwt_values_should_error()
490490
public async Task authorize_should_accept_complex_objects_in_request_object()
491491
{
492492
var someObj = new { foo = new { bar = "bar" }, baz = "baz" };
493-
var someObjJson = JsonConvert.SerializeObject(someObj);
493+
var someObjJson = JsonSerializer.Serialize(someObj);
494494
var someArr = new[] { "a", "b", "c" };
495-
var someArrJson = JsonConvert.SerializeObject(someArr);
495+
var someArrJson = JsonSerializer.Serialize(someArr);
496496

497497

498498
var requestJwt = CreateRequestJwt(
@@ -527,19 +527,19 @@ public async Task authorize_should_accept_complex_objects_in_request_object()
527527
_mockPipeline.LoginRequest.Should().NotBeNull();
528528

529529
_mockPipeline.LoginRequest.Parameters["someObj"].Should().NotBeNull();
530-
var someObj2 = JsonConvert.DeserializeObject(_mockPipeline.LoginRequest.Parameters["someObj"], someObj.GetType());
530+
var someObj2 = JsonSerializer.Deserialize(_mockPipeline.LoginRequest.Parameters["someObj"], someObj.GetType());
531531
someObj.Should().BeEquivalentTo(someObj2);
532532
_mockPipeline.LoginRequest.Parameters["someArr"].Should().NotBeNull();
533-
var someArr2 = JsonConvert.DeserializeObject<string[]>(_mockPipeline.LoginRequest.Parameters["someArr"]);
533+
var someArr2 = JsonSerializer.Deserialize<string[]>(_mockPipeline.LoginRequest.Parameters["someArr"]);
534534
someArr2.Should().Contain(new[] { "a", "c", "b" });
535535
someArr2.Length.Should().Be(3);
536536

537537
_mockPipeline.LoginRequest.RequestObjectValues.Count.Should().Be(13);
538538
_mockPipeline.LoginRequest.RequestObjectValues["someObj"].Should().NotBeNull();
539-
someObj2 = JsonConvert.DeserializeObject(_mockPipeline.LoginRequest.RequestObjectValues["someObj"], someObj.GetType());
539+
someObj2 = JsonSerializer.Deserialize(_mockPipeline.LoginRequest.RequestObjectValues["someObj"], someObj.GetType());
540540
someObj.Should().BeEquivalentTo(someObj2);
541541
_mockPipeline.LoginRequest.RequestObjectValues["someArr"].Should().NotBeNull();
542-
someArr2 = JsonConvert.DeserializeObject<string[]>(_mockPipeline.LoginRequest.Parameters["someArr"]);
542+
someArr2 = JsonSerializer.Deserialize<string[]>(_mockPipeline.LoginRequest.Parameters["someArr"]);
543543
someArr2.Should().Contain(new[] { "a", "c", "b" });
544544
someArr2.Length.Should().Be(3);
545545
}

0 commit comments

Comments
 (0)