Skip to content

Commit 73926a3

Browse files
Ivan KamkinIvan Kamkin
authored andcommitted
Version updated
Newtonsoft.Json replaced with System.Text.Json
1 parent 2ca02d0 commit 73926a3

22 files changed

Lines changed: 105 additions & 107 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Nuget](https://img.shields.io/nuget/v/Aspose.BarCode-Cloud)](https://www.nuget.org/packages/Aspose.BarCode-Cloud/)
77

88
- API version: 4.0
9-
- SDK version: 25.3.0
9+
- SDK version: 25.4.0
1010

1111
## SDK and API Version Compatibility:
1212

@@ -201,7 +201,7 @@ internal static class Program
201201

202202
## Dependencies
203203

204-
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/)
204+
- [System.Text.Json](https://www.nuget.org/packages/System.Text.json)
205205

206206
## Licensing
207207

Tests/ConfigurationTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using Aspose.BarCode.Cloud.Sdk.Api;
4-
using Newtonsoft.Json;
4+
using System.Text.Json;
55
using NUnit.Framework;
66

77
namespace Aspose.BarCode.Cloud.Sdk.Tests
@@ -90,13 +90,11 @@ public void DefaultParamsTest()
9090
[Test]
9191
public void DeserializeTest()
9292
{
93-
using StreamReader file = File.OpenText(Path.Combine(
93+
using FileStream file = File.OpenRead(Path.Combine(
9494
TestContext.CurrentContext.TestDirectory,
9595
"..", "..", "..",
9696
"Configuration.template.json"));
97-
JsonSerializer serializer = new JsonSerializer();
98-
using JsonTextReader reader = new JsonTextReader(file);
99-
Configuration config = serializer.Deserialize<Configuration>(reader);
97+
var config = JsonSerializer.Deserialize<Configuration>(file);
10098

10199
Assert.IsNotNull(config);
102100
Assert.AreEqual("Client Secret from https://dashboard.aspose.cloud/applications", config.ClientSecret);
@@ -131,7 +129,7 @@ public void SerializationTest()
131129
"ApiVersion\":\"4.0\",\"" +
132130
"DefaultHeaders\":{}" +
133131
"}",
134-
JsonConvert.SerializeObject(config));
132+
JsonSerializer.Serialize(config));
135133
}
136134
}
137135
}

Tests/JWTRequestHandlerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
using System.Net;
55
using System.Net.Http;
66
using System.Text;
7+
using System.Text.Json;
78
using System.Threading.Tasks;
89
using Aspose.BarCode.Cloud.Sdk.Api;
910
using Aspose.BarCode.Cloud.Sdk.Internal;
1011
using Aspose.BarCode.Cloud.Sdk.Internal.RequestHandlers;
1112
using Moq;
12-
using Newtonsoft.Json.Linq;
1313
using NUnit.Framework;
1414

1515
namespace Aspose.BarCode.Cloud.Sdk.Tests
@@ -169,9 +169,9 @@ private static void AssertTokenIsValid(string token)
169169
{
170170
string firstPartBeforeDot = new string(token.TakeWhile(c => c != '.').ToArray());
171171
byte[] tokenBytes = Convert.FromBase64String(firstPartBeforeDot);
172-
JObject tokenHeader = JObject.Parse(Encoding.UTF8.GetString(tokenBytes));
172+
JsonElement tokenHeader = JsonDocument.Parse(Encoding.UTF8.GetString(tokenBytes)).RootElement;
173173

174-
Assert.AreEqual("JWT", tokenHeader["typ"]?.ToString());
174+
Assert.AreEqual("JWT", tokenHeader.GetProperty("typ").GetString());
175175
}
176176
}
177177
}

Tests/JwtAuthTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Net.Http;
5+
using System.Text.Json;
56
using System.Threading.Tasks;
67
using Aspose.BarCode.Cloud.Sdk.Api;
78
using Aspose.BarCode.Cloud.Sdk.Model;
8-
9-
using Newtonsoft.Json.Linq;
109
using NUnit.Framework;
1110

1211
namespace Aspose.BarCode.Cloud.Sdk.Tests
@@ -27,8 +26,8 @@ private async Task<string> FetchToken()
2726
FormUrlEncodedContent formContent = new FormUrlEncodedContent(formParams);
2827
HttpResponseMessage response = await new HttpClient().PostAsync(TestConfiguration.TokenUrl, formContent);
2928
response.EnsureSuccessStatusCode();
30-
JObject json = JObject.Parse(await response.Content.ReadAsStringAsync());
31-
string accessToken = Convert.ToString(json["access_token"]);
29+
JsonDocument json = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
30+
string accessToken = json.RootElement.GetProperty("access_token").GetString();
3231
return accessToken;
3332
}
3433

Tests/TestsBase.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
using System.IO;
44
using System.Text;
55
using Aspose.BarCode.Cloud.Sdk.Api;
6-
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Linq;
6+
using System.Text.Json;
87
using NUnit.Framework;
98

109
namespace Aspose.BarCode.Cloud.Sdk.Tests
@@ -36,38 +35,44 @@ private static Configuration LoadTestConfiguration()
3635
"Configuration.json"));
3736
if (File.Exists(configFilename))
3837
{
39-
using StreamReader file = File.OpenText(configFilename);
40-
using JsonTextReader reader = new JsonTextReader(file);
41-
JsonSerializer serializer = new JsonSerializer();
42-
return serializer.Deserialize<Configuration>(reader);
38+
using FileStream file = File.OpenRead(configFilename);
39+
return JsonSerializer.Deserialize<Configuration>(file)
40+
?? throw new Exception("Configuration file is empty or invalid");
4341
}
44-
4542
Configuration config = LoadFromEnv();
46-
4743
return config;
4844
}
4945

5046
private static Configuration LoadFromEnv()
5147
{
52-
string jsonStr = JsonConvert.SerializeObject(new Configuration());
53-
JObject obj = JObject.Parse(jsonStr);
54-
foreach (KeyValuePair<string, JToken> i in obj)
48+
// Serialize default config to JSON then to a dictionary
49+
string jsonStr = JsonSerializer.Serialize(new Configuration());
50+
var dict = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonStr);
51+
52+
if (dict == null)
53+
throw new Exception("Default configuration invalid");
54+
55+
foreach (var key in new List<string>(dict.Keys))
5556
{
56-
if (!(i.Value.Type == JTokenType.String || i.Value.Type == JTokenType.Null))
57-
{
57+
var value = dict[key];
58+
59+
// Accept strings and nulls (JSON null becomes null here)
60+
if (value != null && !(value is string))
5861
continue;
59-
}
6062

61-
string name = i.Key;
62-
string envName = $"{ENV_NAME_PREFIX}{CamelCaseToUpper(name)}";
63+
string envName = $"{ENV_NAME_PREFIX}{CamelCaseToUpper(key)}";
6364
string envValue = Environment.GetEnvironmentVariable(envName);
6465
if (!string.IsNullOrEmpty(envValue))
6566
{
66-
obj[name] = envValue;
67+
dict[key] = envValue;
6768
}
6869
}
69-
70-
return JsonConvert.DeserializeObject<Configuration>(obj.ToString());
70+
// Serialize back and then deserialize to Configuration
71+
string updatedJson = JsonSerializer.Serialize(dict);
72+
var config = JsonSerializer.Deserialize<Configuration>(updatedJson);
73+
if (config == null)
74+
throw new Exception("Failed to create Configuration from environment variables");
75+
return config;
7176
}
7277

7378
private static string CamelCaseToUpper(string name)

examples/GenerateQR/GenerateQR.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
10+
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
1111
</ItemGroup>
1212

1313
</Project>

examples/ReadQR/ReadQR.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
10+
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
1111
</ItemGroup>
1212

1313
</Project>

snippets/Snippets.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
10+
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />
1111
</ItemGroup>
1212

1313
</Project>

snippets/dependency.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.3.0" />
1+
<PackageReference Include="Aspose.BarCode-Cloud" Version="25.4.0" />

src/Api/Configuration.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Converters;
3+
using System.Text.Json.Serialization;
54

65
namespace Aspose.BarCode.Cloud.Sdk.Api
76
{
@@ -71,7 +70,7 @@ public string JwtToken
7170
/// <summary>
7271
/// Authentication type.
7372
/// </summary>
74-
[JsonConverter(typeof(StringEnumConverter))]
73+
[JsonConverter(typeof(JsonStringEnumConverter))]
7574
public AuthType AuthType { get; private set; }
7675

7776
/// <summary>

0 commit comments

Comments
 (0)