Skip to content

Commit 3594a82

Browse files
ivankamkinIvan Kamkin
andauthored
Release 25.4 (#105)
* Version updated Newtonsoft.Json replaced with System.Text.Json * Formatting * Try to suppress build errors * Remove old frameworks Add new 9.0 version Update System.Text.Json version * Suppress warnings * Removed out of support .net versions * Check examples on latest linux and .net version * Fix target framework in example projects --------- Co-authored-by: Ivan Kamkin <234-Ivan.Kamkin@users.noreply.git.saltov.dynabic.com>
1 parent 2ca02d0 commit 3594a82

27 files changed

Lines changed: 109 additions & 123 deletions

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET Core Linux
1+
name: .NET Linux
22

33
on:
44
push:
@@ -16,14 +16,10 @@ jobs:
1616
# and https://github.com/dotnet/core/blob/main/releases.md
1717
# for versions
1818
include:
19-
- dotnet-version: 3.1.x
20-
framework: netcoreapp3.1
21-
- dotnet-version: 5.0.x
22-
framework: net5.0
23-
- dotnet-version: 6.0.x
24-
framework: net6.0
2519
- dotnet-version: 8.0.x
2620
framework: net8.0
21+
- dotnet-version: 9.0.x
22+
framework: net9.0
2723

2824
continue-on-error: true
2925

.github/workflows/test-examples-and-snippets.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88

99
jobs:
1010
build-examples:
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-latest
12+
1213

1314
steps:
1415
- uses: actions/checkout@v4

README.md

Lines changed: 3 additions & 4 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

@@ -27,9 +27,8 @@ This repository contains Aspose.BarCode Cloud SDK for .NET source code. This SDK
2727

2828
Aspose.BarCode Cloud SDK for .NET provides cross-platform bindings for:
2929

30-
- .NET 5 and higher
30+
- .NET 8 and higher
3131
- .NET Standard 2.0 and higher
32-
- .NET Core 3.1 and higher
3332
- .NET Framework 4.6.2 and higher
3433

3534
To use these SDKs, you will need Client Id and Client Secret which can be looked up at [Aspose Cloud Dashboard](https://dashboard.aspose.cloud/applications) (free registration in Aspose Cloud is required for this).
@@ -201,7 +200,7 @@ internal static class Program
201200

202201
## Dependencies
203202

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

206205
## Licensing
207206

Tests/Aspose.BarCode.Cloud.Sdk.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net462;net480;net481;netcoreapp3.1;net5.0;net6.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net462;net480;net481;net8.0;net9.0</TargetFrameworks>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<IsTestProject>true</IsTestProject>
77
<LangVersion>8.0</LangVersion>

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/RecognizeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public async Task RecognizeBase64AsyncTest()
3232
using Stream image = GetTestImage("Test_PostGenerateMultiple.png");
3333

3434
byte[] buffer = new byte[image.Length];
35-
await image.ReadAsync(buffer, 0, buffer.Length);
35+
_ = await image.ReadAsync(buffer, 0, buffer.Length);
3636

3737
// Act
3838
BarcodeResponseList response = await _api.RecognizeBase64Async(

Tests/ScanTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task ScanBase64AsyncTest()
2929

3030
byte[] buffer = new byte[image.Length];
3131

32-
await image.ReadAsync(buffer, 0, buffer.Length);
32+
_ = await image.ReadAsync(buffer, 0, buffer.Length);
3333
// Act
3434
BarcodeResponseList response = await _api.ScanBase64Async(
3535
new ScanBase64Request()

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)

0 commit comments

Comments
 (0)