1
1
using System ;
2
2
using System . Globalization ;
3
3
using System . IO ;
4
- using Newtonsoft . Json ;
4
+ using System . Text . Json ;
5
5
using Flow . Launcher . Infrastructure . Logger ;
6
6
7
7
namespace Flow . Launcher . Infrastructure . Storage
@@ -11,7 +11,7 @@ namespace Flow.Launcher.Infrastructure.Storage
11
11
/// </summary>
12
12
public class JsonStrorage < T >
13
13
{
14
- private readonly JsonSerializerSettings _serializerSettings ;
14
+ private readonly JsonSerializerOptions _serializerSettings ;
15
15
private T _data ;
16
16
// need a new directory name
17
17
public const string DirectoryName = "Settings" ;
@@ -24,10 +24,9 @@ internal JsonStrorage()
24
24
{
25
25
// use property initialization instead of DefaultValueAttribute
26
26
// easier and flexible for default value of object
27
- _serializerSettings = new JsonSerializerSettings
27
+ _serializerSettings = new JsonSerializerOptions
28
28
{
29
- ObjectCreationHandling = ObjectCreationHandling . Replace ,
30
- NullValueHandling = NullValueHandling . Ignore
29
+ IgnoreNullValues = false
31
30
} ;
32
31
}
33
32
@@ -56,7 +55,7 @@ private void Deserialize(string searlized)
56
55
{
57
56
try
58
57
{
59
- _data = JsonConvert . DeserializeObject < T > ( searlized , _serializerSettings ) ;
58
+ _data = JsonSerializer . Deserialize < T > ( searlized , _serializerSettings ) ;
60
59
}
61
60
catch ( JsonException e )
62
61
{
@@ -77,7 +76,7 @@ private void LoadDefault()
77
76
BackupOriginFile ( ) ;
78
77
}
79
78
80
- _data = JsonConvert . DeserializeObject < T > ( "{}" , _serializerSettings ) ;
79
+ _data = JsonSerializer . Deserialize < T > ( "{}" , _serializerSettings ) ;
81
80
Save ( ) ;
82
81
}
83
82
@@ -94,7 +93,8 @@ private void BackupOriginFile()
94
93
95
94
public void Save ( )
96
95
{
97
- string serialized = JsonConvert . SerializeObject ( _data , Formatting . Indented ) ;
96
+ string serialized = JsonSerializer . Serialize ( _data , new JsonSerializerOptions ( ) { WriteIndented = true } ) ;
97
+
98
98
File . WriteAllText ( FilePath , serialized ) ;
99
99
}
100
100
}
0 commit comments