11using System ;
22using System . Globalization ;
33using System . IO ;
4- using Newtonsoft . Json ;
4+ using System . Text . Json ;
55using Flow . Launcher . Infrastructure . Logger ;
66
77namespace Flow . Launcher . Infrastructure . Storage
@@ -11,7 +11,7 @@ namespace Flow.Launcher.Infrastructure.Storage
1111 /// </summary>
1212 public class JsonStrorage < T >
1313 {
14- private readonly JsonSerializerSettings _serializerSettings ;
14+ private readonly JsonSerializerOptions _serializerSettings ;
1515 private T _data ;
1616 // need a new directory name
1717 public const string DirectoryName = "Settings" ;
@@ -24,10 +24,9 @@ internal JsonStrorage()
2424 {
2525 // use property initialization instead of DefaultValueAttribute
2626 // easier and flexible for default value of object
27- _serializerSettings = new JsonSerializerSettings
27+ _serializerSettings = new JsonSerializerOptions
2828 {
29- ObjectCreationHandling = ObjectCreationHandling . Replace ,
30- NullValueHandling = NullValueHandling . Ignore
29+ IgnoreNullValues = false
3130 } ;
3231 }
3332
@@ -56,7 +55,7 @@ private void Deserialize(string searlized)
5655 {
5756 try
5857 {
59- _data = JsonConvert . DeserializeObject < T > ( searlized , _serializerSettings ) ;
58+ _data = JsonSerializer . Deserialize < T > ( searlized , _serializerSettings ) ;
6059 }
6160 catch ( JsonException e )
6261 {
@@ -77,7 +76,7 @@ private void LoadDefault()
7776 BackupOriginFile ( ) ;
7877 }
7978
80- _data = JsonConvert . DeserializeObject < T > ( "{}" , _serializerSettings ) ;
79+ _data = JsonSerializer . Deserialize < T > ( "{}" , _serializerSettings ) ;
8180 Save ( ) ;
8281 }
8382
@@ -94,7 +93,8 @@ private void BackupOriginFile()
9493
9594 public void Save ( )
9695 {
97- string serialized = JsonConvert . SerializeObject ( _data , Formatting . Indented ) ;
96+ string serialized = JsonSerializer . Serialize ( _data , new JsonSerializerOptions ( ) { WriteIndented = true } ) ;
97+
9898 File . WriteAllText ( FilePath , serialized ) ;
9999 }
100100 }
0 commit comments