Skip to content

Commit 803338f

Browse files
Merge pull request #46 from sharpcode-it/engineering87-develop
Migrate from Newtonsoft.Json to System.Text.Json
2 parents 9e848ed + deff775 commit 803338f

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

SharpHelpers/SharpHelpers/ObjectExtensions/ObjectSerializationhelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.IO;
44
using System.Xml;
55
using System.Xml.Serialization;
6-
using Newtonsoft.Json;
6+
using System.Text.Json;
77

88
namespace SharpCoding.SharpHelpers.ObjectExtensions
99
{
@@ -16,7 +16,7 @@ public static class ObjectSerializationHelper
1616
/// <returns></returns>
1717
public static string SerializeToJson(this object istance)
1818
{
19-
return istance == null ? string.Empty : JsonConvert.SerializeObject(istance);
19+
return istance == null ? string.Empty : JsonSerializer.Serialize(istance);
2020
}
2121

2222
/// <summary>
@@ -27,7 +27,7 @@ public static string SerializeToJson(this object istance)
2727
/// <returns></returns>
2828
public static T DeserializeFromJson<T>(this string istance) where T : class
2929
{
30-
return string.IsNullOrEmpty(istance) ? default : JsonConvert.DeserializeObject<T>(istance);
30+
return string.IsNullOrEmpty(istance) ? default : JsonSerializer.Deserialize<T>(istance);
3131
}
3232

3333
/// <summary>

SharpHelpers/SharpHelpers/SharpHelpers.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
<PackageIcon>ico.png</PackageIcon>
2121
<PackageIconUrl />
2222
</PropertyGroup>
23-
<ItemGroup>
24-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
25-
</ItemGroup>
2623

2724
<ItemGroup>
2825
<None Include="..\..\LICENSE">
@@ -38,4 +35,8 @@
3835
<ItemGroup>
3936
<Compile Remove="RegistryHelpers.cs" />
4037
</ItemGroup>
38+
39+
<ItemGroup>
40+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
41+
</ItemGroup>
4142
</Project>

SharpHelpers/SharpHelpers/StringHelper.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Globalization;
66
using System.Linq;
77
using System.Text;
8-
using Newtonsoft.Json;
8+
using System.Text.Json;
99
using System.Text.RegularExpressions;
1010
using SharpCoding.SharpHelpers.DomainModel;
1111
using SharpCoding.SharpHelpers.PrivateMethods;
@@ -223,8 +223,13 @@ public static string Right(this string str, int length)
223223
/// <param name="strJson"></param>
224224
public static T JsonToObject<T>(this string strJson)
225225
{
226-
return JsonConvert.DeserializeObject<T>(strJson,
227-
new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
226+
var options = new JsonSerializerOptions
227+
{
228+
ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles,
229+
PropertyNameCaseInsensitive = true
230+
};
231+
232+
return JsonSerializer.Deserialize<T>(strJson, options);
228233
}
229234

230235
/// <summary>

0 commit comments

Comments
 (0)