diff --git a/JL.Core/Audio/AudioUtils.cs b/JL.Core/Audio/AudioUtils.cs index 072b49e7..adbc8961 100644 --- a/JL.Core/Audio/AudioUtils.cs +++ b/JL.Core/Audio/AudioUtils.cs @@ -201,14 +201,14 @@ public static async Task GetAndPlayAudio(string foundSpelling, string? reading) public static Task SerializeAudioSources() { return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AudioSourceConfig.json"), - JsonSerializer.Serialize(AudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(AudioSources, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } public static Task CreateDefaultAudioSourceConfig() { _ = Directory.CreateDirectory(Utils.ConfigPath); return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AudioSourceConfig.json"), - JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } internal static async Task DeserializeAudioSources() @@ -217,7 +217,7 @@ internal static async Task DeserializeAudioSources() await using (fileStream.ConfigureAwait(false)) { Dictionary? deserializedAudioSources = await JsonSerializer - .DeserializeAsync>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(fileStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false); if (deserializedAudioSources is not null) { diff --git a/JL.Core/Config/StatsDBUtils.cs b/JL.Core/Config/StatsDBUtils.cs index b1c64ff5..5397a05a 100644 --- a/JL.Core/Config/StatsDBUtils.cs +++ b/JL.Core/Config/StatsDBUtils.cs @@ -10,7 +10,7 @@ public static class StatsDBUtils { public static void InsertStats(SqliteConnection connection, Stats stats, int profileId) { - InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId); + InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId); } private static void InsertStats(SqliteConnection connection, string stats, int profileId) @@ -29,7 +29,7 @@ INSERT INTO stats (profile_id, value) private static void UpdateStats(SqliteConnection connection, Stats stats, int profileId) { - UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId); + UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId); } private static void UpdateStats(SqliteConnection connection, string stats, int profileId) @@ -90,7 +90,7 @@ FROM stats string? statsValue = (string?)command.ExecuteScalar(); return statsValue is not null - ? JsonSerializer.Deserialize(statsValue, Utils.s_jsoNotIgnoringNullWithEnumConverter) + ? JsonSerializer.Deserialize(statsValue, Utils.s_jsoWithEnumConverter) : null; } diff --git a/JL.Core/Deconjugation/DeconjugatorUtils.cs b/JL.Core/Deconjugation/DeconjugatorUtils.cs index 5a052867..5b2d8220 100644 --- a/JL.Core/Deconjugation/DeconjugatorUtils.cs +++ b/JL.Core/Deconjugation/DeconjugatorUtils.cs @@ -10,7 +10,7 @@ public static async Task DeserializeRules() FileStream fileStream = File.OpenRead(Path.Join(Utils.ResourcesPath, "deconjugation_rules.json")); await using (fileStream.ConfigureAwait(false)) { - Deconjugator.Rules = (await JsonSerializer.DeserializeAsync(fileStream, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false))!; + Deconjugator.Rules = (await JsonSerializer.DeserializeAsync(fileStream, Utils.s_jso).ConfigureAwait(false))!; } int rulesLength = Deconjugator.Rules.Length; diff --git a/JL.Core/Dicts/DictUtils.cs b/JL.Core/Dicts/DictUtils.cs index 200cbe6e..1552b10a 100644 --- a/JL.Core/Dicts/DictUtils.cs +++ b/JL.Core/Dicts/DictUtils.cs @@ -1361,13 +1361,13 @@ public static Task CreateDefaultDictsConfig() { _ = Directory.CreateDirectory(Utils.ConfigPath); return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"), - JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } public static Task SerializeDicts() { return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"), - JsonSerializer.Serialize(Dicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(Dicts, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } internal static async Task DeserializeDicts() @@ -1376,7 +1376,7 @@ internal static async Task DeserializeDicts() await using (dictStream.ConfigureAwait(false)) { Dictionary? deserializedDicts = await JsonSerializer - .DeserializeAsync>(dictStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(dictStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false); if (deserializedDicts is not null) { diff --git a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs index 2b4124e1..154538e0 100644 --- a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs +++ b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs @@ -95,8 +95,8 @@ INSERT INTO record_search_key(record_id, search_key) _ = insertRecordCommand.Parameters["@id"].Value = id; _ = insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling; _ = insertRecordCommand.Parameters["@reading"].Value = record.Reading is not null ? record.Reading : DBNull.Value; - _ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull); + _ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso); _ = insertRecordCommand.ExecuteNonQuery(); _ = insertSearchKeyCommand.Parameters["@record_id"].Value = id; @@ -170,10 +170,10 @@ INSERT INTO record_search_key(record_id, search_key) string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jso); } - string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jso)!; if (results.TryGetValue(searchKey, out IList? result)) { @@ -234,7 +234,7 @@ FROM record r while (dataReader.Read()) { EpwingNazekaRecord record = GetRecord(dataReader); - List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; + List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!; for (int i = 0; i < searchKeys.Count; i++) { string searchKey = searchKeys[i]; @@ -270,10 +270,10 @@ private static EpwingNazekaRecord GetRecord(SqliteDataReader dataReader) string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jso); } - string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jso)!; return new EpwingNazekaRecord(primarySpelling, reading, alternativeSpellings, definitions); } diff --git a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs index c5931ed5..1959823c 100644 --- a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs +++ b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs @@ -20,7 +20,7 @@ public static async Task Load(Dict dict) FileStream fileStream = File.OpenRead(fullPath); await using (fileStream.ConfigureAwait(false)) { - jsonObjects = await JsonSerializer.DeserializeAsync>(fileStream, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false); + jsonObjects = await JsonSerializer.DeserializeAsync>(fileStream, Utils.s_jso).ConfigureAwait(false); } IDictionary> nazekaEpwingDict = dict.Contents; diff --git a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanDBManager.cs b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanDBManager.cs index d5a5b05d..453b75da 100644 --- a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanDBManager.cs +++ b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanDBManager.cs @@ -98,9 +98,9 @@ INSERT INTO record_search_key(record_id, search_key) _ = insertRecordCommand.Parameters["@id"].Value = id; _ = insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling; _ = insertRecordCommand.Parameters["@reading"].Value = record.Reading is not null ? record.Reading : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull); - _ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_jsoNotIgnoringNull) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso); + _ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_jso) : DBNull.Value; _ = insertRecordCommand.ExecuteNonQuery(); _ = insertSearchKeyCommand.Parameters["@record_id"].Value = id; @@ -221,7 +221,7 @@ FROM record r while (dataReader.Read()) { EpwingYomichanRecord record = GetRecord(dataReader); - List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; + List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!; for (int i = 0; i < searchKeys.Count; i++) { string searchKey = searchKeys[i]; @@ -255,18 +255,18 @@ private static EpwingYomichanRecord GetRecord(SqliteDataReader dataReader) reading = readingFromDB; } - string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jso)!; string[]? wordClasses = null; if (dataReader[nameof(wordClasses)] is string wordClassesFromDB) { - wordClasses = JsonSerializer.Deserialize(wordClassesFromDB, Utils.s_jsoNotIgnoringNull); + wordClasses = JsonSerializer.Deserialize(wordClassesFromDB, Utils.s_jso); } string[]? definitionTags = null; if (dataReader[nameof(definitionTags)] is string definitionTagsFromDB) { - definitionTags = JsonSerializer.Deserialize(definitionTagsFromDB, Utils.s_jsoNotIgnoringNull); + definitionTags = JsonSerializer.Deserialize(definitionTagsFromDB, Utils.s_jso); } return new EpwingYomichanRecord(primarySpelling, reading, definitions, wordClasses, definitionTags); diff --git a/JL.Core/Dicts/JMdict/JmdictDBManager.cs b/JL.Core/Dicts/JMdict/JmdictDBManager.cs index 1c93f3c7..47e4c7de 100644 --- a/JL.Core/Dicts/JMdict/JmdictDBManager.cs +++ b/JL.Core/Dicts/JMdict/JmdictDBManager.cs @@ -127,22 +127,22 @@ INSERT INTO record_search_key(record_id, search_key) insertRecordCommand.Parameters["@id"].Value = id; insertRecordCommand.Parameters["@edict_id"].Value = record.Id; insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling; - insertRecordCommand.Parameters["@primary_spelling_orthography_info"].Value = record.PrimarySpellingOrthographyInfo is not null ? JsonSerializer.Serialize(record.PrimarySpellingOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@alternative_spellings_orthography_info"].Value = record.AlternativeSpellingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.AlternativeSpellingsOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@readings_orthography_info"].Value = record.ReadingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.ReadingsOrthographyInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@reading_restrictions"].Value = record.ReadingRestrictions is not null ? JsonSerializer.Serialize(record.ReadingRestrictions, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull); - insertRecordCommand.Parameters["@glossary_info"].Value = record.DefinitionInfo is not null ? JsonSerializer.Serialize(record.DefinitionInfo, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@part_of_speech"].Value = JsonSerializer.Serialize(record.WordClasses, Utils.s_jsoNotIgnoringNull); - insertRecordCommand.Parameters["@spelling_restrictions"].Value = record.SpellingRestrictions is not null ? JsonSerializer.Serialize(record.SpellingRestrictions, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@fields"].Value = record.Fields is not null ? JsonSerializer.Serialize(record.Fields, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@misc"].Value = record.Misc is not null ? JsonSerializer.Serialize(record.Misc, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@dialects"].Value = record.Dialects is not null ? JsonSerializer.Serialize(record.Dialects, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@loanword_etymology"].Value = record.LoanwordEtymology is not null ? JsonSerializer.Serialize(record.LoanwordEtymology, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@cross_references"].Value = record.RelatedTerms is not null ? JsonSerializer.Serialize(record.RelatedTerms, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - insertRecordCommand.Parameters["@antonyms"].Value = record.Antonyms is not null ? JsonSerializer.Serialize(record.Antonyms, Utils.s_jsoNotIgnoringNull) : DBNull.Value; + insertRecordCommand.Parameters["@primary_spelling_orthography_info"].Value = record.PrimarySpellingOrthographyInfo is not null ? JsonSerializer.Serialize(record.PrimarySpellingOrthographyInfo, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@alternative_spellings_orthography_info"].Value = record.AlternativeSpellingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.AlternativeSpellingsOrthographyInfo, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@readings_orthography_info"].Value = record.ReadingsOrthographyInfo is not null ? JsonSerializer.Serialize(record.ReadingsOrthographyInfo, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@reading_restrictions"].Value = record.ReadingRestrictions is not null ? JsonSerializer.Serialize(record.ReadingRestrictions, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso); + insertRecordCommand.Parameters["@glossary_info"].Value = record.DefinitionInfo is not null ? JsonSerializer.Serialize(record.DefinitionInfo, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@part_of_speech"].Value = JsonSerializer.Serialize(record.WordClasses, Utils.s_jso); + insertRecordCommand.Parameters["@spelling_restrictions"].Value = record.SpellingRestrictions is not null ? JsonSerializer.Serialize(record.SpellingRestrictions, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@fields"].Value = record.Fields is not null ? JsonSerializer.Serialize(record.Fields, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@misc"].Value = record.Misc is not null ? JsonSerializer.Serialize(record.Misc, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@dialects"].Value = record.Dialects is not null ? JsonSerializer.Serialize(record.Dialects, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@loanword_etymology"].Value = record.LoanwordEtymology is not null ? JsonSerializer.Serialize(record.LoanwordEtymology, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@cross_references"].Value = record.RelatedTerms is not null ? JsonSerializer.Serialize(record.RelatedTerms, Utils.s_jso) : DBNull.Value; + insertRecordCommand.Parameters["@antonyms"].Value = record.Antonyms is not null ? JsonSerializer.Serialize(record.Antonyms, Utils.s_jso) : DBNull.Value; _ = insertRecordCommand.ExecuteNonQuery(); int keyCount = keys.Count; @@ -272,7 +272,7 @@ FROM record r { JmdictRecord record = GetRecord(dataReader); - List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; + List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!; for (int i = 0; i < searchKeys.Count; i++) { string searchKey = searchKeys[i]; @@ -303,88 +303,88 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader) string[]? primarySpellingOrthographyInfo = null; if (dataReader[nameof(primarySpellingOrthographyInfo)] is string primarySpellingOrthographyInfoFromDB) { - primarySpellingOrthographyInfo = JsonSerializer.Deserialize(primarySpellingOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull); + primarySpellingOrthographyInfo = JsonSerializer.Deserialize(primarySpellingOrthographyInfoFromDB, Utils.s_jso); } string[]?[]? spellingRestrictions = null; if (dataReader[nameof(spellingRestrictions)] is string spellingRestrictionsFromDB) { - spellingRestrictions = JsonSerializer.Deserialize(spellingRestrictionsFromDB, Utils.s_jsoNotIgnoringNull); + spellingRestrictions = JsonSerializer.Deserialize(spellingRestrictionsFromDB, Utils.s_jso); } string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jso); } string[]?[]? alternativeSpellingsOrthographyInfo = null; if (dataReader[nameof(alternativeSpellingsOrthographyInfo)] is string alternativeSpellingsOrthographyInfoFromDB) { - alternativeSpellingsOrthographyInfo = JsonSerializer.Deserialize(alternativeSpellingsOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull); + alternativeSpellingsOrthographyInfo = JsonSerializer.Deserialize(alternativeSpellingsOrthographyInfoFromDB, Utils.s_jso); } string[]? readings = null; if (dataReader[nameof(readings)] is string readingsFromDB) { - readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jsoNotIgnoringNull); + readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jso); } string[]?[]? readingRestrictions = null; if (dataReader[nameof(readingRestrictions)] is string readingRestrictionsFromDB) { - readingRestrictions = JsonSerializer.Deserialize(readingRestrictionsFromDB, Utils.s_jsoNotIgnoringNull); + readingRestrictions = JsonSerializer.Deserialize(readingRestrictionsFromDB, Utils.s_jso); } string[]?[]? readingsOrthographyInfo = null; if (dataReader[nameof(readingsOrthographyInfo)] is string readingsOrthographyInfoFromDB) { - readingsOrthographyInfo = JsonSerializer.Deserialize(readingsOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull); + readingsOrthographyInfo = JsonSerializer.Deserialize(readingsOrthographyInfoFromDB, Utils.s_jso); } - string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; - string[][] wordClasses = JsonSerializer.Deserialize(dataReader.GetString(nameof(wordClasses)), Utils.s_jsoNotIgnoringNull)!; + string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jso)!; + string[][] wordClasses = JsonSerializer.Deserialize(dataReader.GetString(nameof(wordClasses)), Utils.s_jso)!; string[]?[]? fields = null; if (dataReader[nameof(fields)] is string fieldsFromDB) { - fields = JsonSerializer.Deserialize(fieldsFromDB, Utils.s_jsoNotIgnoringNull); + fields = JsonSerializer.Deserialize(fieldsFromDB, Utils.s_jso); } string[]?[]? misc = null; if (dataReader[nameof(misc)] is string miscFromDB) { - misc = JsonSerializer.Deserialize(miscFromDB, Utils.s_jsoNotIgnoringNull); + misc = JsonSerializer.Deserialize(miscFromDB, Utils.s_jso); } string?[]? definitionInfo = null; if (dataReader[nameof(definitionInfo)] is string definitionInfoFromDB) { - definitionInfo = JsonSerializer.Deserialize(definitionInfoFromDB, Utils.s_jsoNotIgnoringNull); + definitionInfo = JsonSerializer.Deserialize(definitionInfoFromDB, Utils.s_jso); } string[]?[]? dialects = null; if (dataReader[nameof(dialects)] is string dialectsFromDB) { - dialects = JsonSerializer.Deserialize(dialectsFromDB, Utils.s_jsoNotIgnoringNull); + dialects = JsonSerializer.Deserialize(dialectsFromDB, Utils.s_jso); } LoanwordSource[]?[]? loanwordEtymology = null; if (dataReader[nameof(loanwordEtymology)] is string loanwordEtymologyFromDB) { - loanwordEtymology = JsonSerializer.Deserialize(loanwordEtymologyFromDB, Utils.s_jsoNotIgnoringNull); + loanwordEtymology = JsonSerializer.Deserialize(loanwordEtymologyFromDB, Utils.s_jso); } string[]?[]? relatedTerms = null; if (dataReader[nameof(relatedTerms)] is string relatedTermsFromDB) { - relatedTerms = JsonSerializer.Deserialize(relatedTermsFromDB, Utils.s_jsoNotIgnoringNull); + relatedTerms = JsonSerializer.Deserialize(relatedTermsFromDB, Utils.s_jso); } string[]?[]? antonyms = null; if (dataReader[nameof(antonyms)] is string antonymsFromDB) { - antonyms = JsonSerializer.Deserialize(antonymsFromDB, Utils.s_jsoNotIgnoringNull); + antonyms = JsonSerializer.Deserialize(antonymsFromDB, Utils.s_jso); } return new JmdictRecord(id, primarySpelling, primarySpellingOrthographyInfo, alternativeSpellings, alternativeSpellingsOrthographyInfo, readings, readingsOrthographyInfo, definitions, wordClasses, spellingRestrictions, readingRestrictions, fields, misc, definitionInfo, dialects, loanwordEtymology, relatedTerms, antonyms); diff --git a/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs b/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs index 040bab63..3ecdab99 100644 --- a/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs +++ b/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs @@ -70,10 +70,10 @@ INSERT INTO record (id, jmnedict_id, primary_spelling, primary_spelling_in_hirag _ = insertRecordCommand.Parameters["@jmnedict_id"].Value = record.Id; _ = insertRecordCommand.Parameters["@primary_spelling"].Value = record.PrimarySpelling; _ = insertRecordCommand.Parameters["@primary_spelling_in_hiragana"].Value = JapaneseUtils.KatakanaToHiragana(record.PrimarySpelling); - _ = insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jsoNotIgnoringNull); - _ = insertRecordCommand.Parameters["@name_types"].Value = JsonSerializer.Serialize(record.NameTypes, Utils.s_jsoNotIgnoringNull); + _ = insertRecordCommand.Parameters["@readings"].Value = record.Readings is not null ? JsonSerializer.Serialize(record.Readings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_jso); + _ = insertRecordCommand.Parameters["@name_types"].Value = JsonSerializer.Serialize(record.NameTypes, Utils.s_jso); _ = insertRecordCommand.ExecuteNonQuery(); ++id; @@ -194,17 +194,17 @@ private static JmnedictRecord GetRecord(SqliteDataReader dataReader) string[]? readings = null; if (dataReader[nameof(readings)] is string readingsFromDB) { - readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jsoNotIgnoringNull); + readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jso); } string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jso); } - string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; - string[][] nameTypes = JsonSerializer.Deserialize(dataReader.GetString(nameof(nameTypes)), Utils.s_jsoNotIgnoringNull)!; + string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jso)!; + string[][] nameTypes = JsonSerializer.Deserialize(dataReader.GetString(nameof(nameTypes)), Utils.s_jso)!; return new JmnedictRecord(id, primarySpelling, alternativeSpellings, readings, definitions, nameTypes); } diff --git a/JL.Core/Dicts/KANJIDIC/KanjidicDBManager.cs b/JL.Core/Dicts/KANJIDIC/KanjidicDBManager.cs index 4209544b..91b6d135 100644 --- a/JL.Core/Dicts/KANJIDIC/KanjidicDBManager.cs +++ b/JL.Core/Dicts/KANJIDIC/KanjidicDBManager.cs @@ -83,11 +83,11 @@ INSERT INTO record (kanji, on_readings, kun_readings, nanori_readings, radical_n { KanjidicRecord kanjidicRecord = (KanjidicRecord)record; _ = insertRecordCommand.Parameters["@kanji"].Value = kanji; - _ = insertRecordCommand.Parameters["@on_readings"].Value = kanjidicRecord.OnReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.OnReadings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@kun_readings"].Value = kanjidicRecord.KunReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.KunReadings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@nanori_readings"].Value = kanjidicRecord.NanoriReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.NanoriReadings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@radical_names"].Value = kanjidicRecord.RadicalNames is not null ? JsonSerializer.Serialize(kanjidicRecord.RadicalNames, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = kanjidicRecord.Definitions is not null ? JsonSerializer.Serialize(kanjidicRecord.Definitions, Utils.s_jsoNotIgnoringNull) : DBNull.Value; + _ = insertRecordCommand.Parameters["@on_readings"].Value = kanjidicRecord.OnReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.OnReadings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@kun_readings"].Value = kanjidicRecord.KunReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.KunReadings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@nanori_readings"].Value = kanjidicRecord.NanoriReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.NanoriReadings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@radical_names"].Value = kanjidicRecord.RadicalNames is not null ? JsonSerializer.Serialize(kanjidicRecord.RadicalNames, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary"].Value = kanjidicRecord.Definitions is not null ? JsonSerializer.Serialize(kanjidicRecord.Definitions, Utils.s_jso) : DBNull.Value; _ = insertRecordCommand.Parameters["@stroke_count"].Value = kanjidicRecord.StrokeCount; _ = insertRecordCommand.Parameters["@grade"].Value = kanjidicRecord.Grade; _ = insertRecordCommand.Parameters["@frequency"].Value = kanjidicRecord.Frequency; @@ -164,31 +164,31 @@ private static KanjidicRecord GetRecord(SqliteDataReader dataReader) string[]? onReadings = null; if (dataReader[nameof(onReadings)] is string onReadingsFromDB) { - onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jsoNotIgnoringNull); + onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jso); } string[]? kunReadings = null; if (dataReader[nameof(kunReadings)] is string kunReadingsFromDB) { - kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jsoNotIgnoringNull); + kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jso); } string[]? nanoriReadings = null; if (dataReader[nameof(nanoriReadings)] is string nanoriReadingsFromDB) { - nanoriReadings = JsonSerializer.Deserialize(nanoriReadingsFromDB, Utils.s_jsoNotIgnoringNull); + nanoriReadings = JsonSerializer.Deserialize(nanoriReadingsFromDB, Utils.s_jso); } string[]? radicalNames = null; if (dataReader[nameof(radicalNames)] is string radicalNamesFromDB) { - radicalNames = JsonSerializer.Deserialize(radicalNamesFromDB, Utils.s_jsoNotIgnoringNull); + radicalNames = JsonSerializer.Deserialize(radicalNamesFromDB, Utils.s_jso); } string[]? definitions = null; if (dataReader[nameof(definitions)] is string definitionsFromDB) { - definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jsoNotIgnoringNull); + definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jso); } byte strokeCount = dataReader.GetByte(nameof(strokeCount)); diff --git a/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs b/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs index ab99a9fa..27e5c146 100644 --- a/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs +++ b/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs @@ -76,10 +76,10 @@ INSERT INTO record (id, kanji, on_readings, kun_readings, glossary, stats) YomichanKanjiRecord yomichanKanjiRecord = (YomichanKanjiRecord)record; _ = insertRecordCommand.Parameters["@id"].Value = id; _ = insertRecordCommand.Parameters["@kanji"].Value = kanji; - _ = insertRecordCommand.Parameters["@on_readings"].Value = yomichanKanjiRecord.OnReadings is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.OnReadings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@kun_readings"].Value = yomichanKanjiRecord.KunReadings is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.KunReadings, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = yomichanKanjiRecord.Definitions is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Definitions, Utils.s_jsoNotIgnoringNull) : DBNull.Value; - _ = insertRecordCommand.Parameters["@stats"].Value = yomichanKanjiRecord.Stats is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Stats, Utils.s_jsoNotIgnoringNull) : DBNull.Value; + _ = insertRecordCommand.Parameters["@on_readings"].Value = yomichanKanjiRecord.OnReadings is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.OnReadings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@kun_readings"].Value = yomichanKanjiRecord.KunReadings is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.KunReadings, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@glossary"].Value = yomichanKanjiRecord.Definitions is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Definitions, Utils.s_jso) : DBNull.Value; + _ = insertRecordCommand.Parameters["@stats"].Value = yomichanKanjiRecord.Stats is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Stats, Utils.s_jso) : DBNull.Value; _ = insertRecordCommand.ExecuteNonQuery(); ++id; @@ -168,25 +168,25 @@ private static YomichanKanjiRecord GetRecord(SqliteDataReader dataReader) string[]? onReadings = null; if (dataReader[nameof(onReadings)] is string onReadingsFromDB) { - onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jsoNotIgnoringNull); + onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jso); } string[]? kunReadings = null; if (dataReader[nameof(kunReadings)] is string kunReadingsFromDB) { - kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jsoNotIgnoringNull); + kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jso); } string[]? definitions = null; if (dataReader[nameof(definitions)] is string definitionsFromDB) { - definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jsoNotIgnoringNull); + definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jso); } string[]? stats = null; if (dataReader[nameof(stats)] is string statsFromDB) { - stats = JsonSerializer.Deserialize(statsFromDB, Utils.s_jsoNotIgnoringNull); + stats = JsonSerializer.Deserialize(statsFromDB, Utils.s_jso); } return new YomichanKanjiRecord(onReadings, kunReadings, definitions, stats); diff --git a/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs b/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs index b274d727..6e2de321 100644 --- a/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs +++ b/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs @@ -23,7 +23,7 @@ public static async Task Load(Dict dict) await using (fileStream.ConfigureAwait(false)) { jsonObjects = await JsonSerializer - .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) + .DeserializeAsync>>(fileStream, Utils.s_jso) .ConfigureAwait(false); } diff --git a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs index 2fa56764..9f0d0f68 100644 --- a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs +++ b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs @@ -241,7 +241,7 @@ FROM record r while (dataReader.Read()) { PitchAccentRecord record = GetRecord(dataReader); - List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; + List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!; for (int i = 0; i < searchKeys.Count; i++) { string searchKey = searchKeys[i]; diff --git a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs index 4ecaebcd..5b1d1c96 100644 --- a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs +++ b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs @@ -25,7 +25,7 @@ public static async Task Load(Dict dict) await using (fileStream.ConfigureAwait(false)) { jsonObjects = await JsonSerializer - .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) + .DeserializeAsync>>(fileStream, Utils.s_jso) .ConfigureAwait(false); } diff --git a/JL.Core/Freqs/FreqDBManager.cs b/JL.Core/Freqs/FreqDBManager.cs index 18c0cb4d..a39af4a4 100644 --- a/JL.Core/Freqs/FreqDBManager.cs +++ b/JL.Core/Freqs/FreqDBManager.cs @@ -227,7 +227,7 @@ FROM record r { FrequencyRecord record = GetRecord(dataReader); - List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; + List searchKeys = JsonSerializer.Deserialize>(dataReader.GetString(nameof(searchKeys)), Utils.s_jso)!; for (int i = 0; i < searchKeys.Count; i++) { string searchKey = searchKeys[i]; diff --git a/JL.Core/Freqs/FreqUtils.cs b/JL.Core/Freqs/FreqUtils.cs index 8f569135..89389634 100644 --- a/JL.Core/Freqs/FreqUtils.cs +++ b/JL.Core/Freqs/FreqUtils.cs @@ -333,13 +333,13 @@ public static Task CreateDefaultFreqsConfig() { _ = Directory.CreateDirectory(Utils.ConfigPath); return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "freqs.json"), - JsonSerializer.Serialize(s_builtInFreqs, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(s_builtInFreqs, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } public static Task SerializeFreqs() { return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "freqs.json"), - JsonSerializer.Serialize(FreqDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(FreqDicts, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)); } internal static async Task DeserializeFreqs() @@ -348,7 +348,7 @@ internal static async Task DeserializeFreqs() await using (fileStream.ConfigureAwait(false)) { Dictionary? deserializedFreqs = await JsonSerializer - .DeserializeAsync>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(fileStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false); if (deserializedFreqs is not null) { diff --git a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs index cf6a204e..92d2b1ed 100644 --- a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs +++ b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs @@ -20,7 +20,7 @@ public static async Task Load(Freq freq) await using (fileStream.ConfigureAwait(false)) { frequencyJson = await JsonSerializer - .DeserializeAsync>>>(fileStream, Utils.s_jsoNotIgnoringNull) + .DeserializeAsync>>>(fileStream, Utils.s_jso) .ConfigureAwait(false); } diff --git a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs index 8622bbf4..7831256c 100644 --- a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs +++ b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs @@ -25,7 +25,7 @@ public static async Task Load(Freq freq) await using (fileStream.ConfigureAwait(false)) { frequencyJson = await JsonSerializer - .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) + .DeserializeAsync>>(fileStream, Utils.s_jso) .ConfigureAwait(false); } diff --git a/JL.Core/Mining/Anki/AnkiConfig.cs b/JL.Core/Mining/Anki/AnkiConfig.cs index 5602d7d5..51c71f55 100644 --- a/JL.Core/Mining/Anki/AnkiConfig.cs +++ b/JL.Core/Mining/Anki/AnkiConfig.cs @@ -30,7 +30,7 @@ public static async Task WriteAnkiConfig(Dictionary ankiCo { _ = Directory.CreateDirectory(Utils.ConfigPath); await File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AnkiConfig.json"), - JsonSerializer.Serialize(ankiConfig, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)).ConfigureAwait(false); + JsonSerializer.Serialize(ankiConfig, Utils.s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation)).ConfigureAwait(false); s_ankiConfigDict = ankiConfig; } @@ -58,7 +58,7 @@ await File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AnkiConfig.json"), await using (ankiConfigStream.ConfigureAwait(false)) { s_ankiConfigDict = await JsonSerializer.DeserializeAsync>(ankiConfigStream, - Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); + Utils.s_jsoWithEnumConverter).ConfigureAwait(false); } return s_ankiConfigDict; diff --git a/JL.Core/Mining/Anki/AnkiConnect.cs b/JL.Core/Mining/Anki/AnkiConnect.cs index 25f67032..3113d78d 100644 --- a/JL.Core/Mining/Anki/AnkiConnect.cs +++ b/JL.Core/Mining/Anki/AnkiConnect.cs @@ -72,7 +72,7 @@ public static async Task Sync() try { // AnkiConnect doesn't like null values - using StringContent payload = new(JsonSerializer.Serialize(req, Utils.s_jsoIgnoringNull)); + using StringContent payload = new(JsonSerializer.Serialize(req, Utils.s_jsoIgnoringWhenWritingNull)); Utils.Logger.Information("Sending: {Payload}", await payload.ReadAsStringAsync().ConfigureAwait(false)); using HttpResponseMessage postResponse = await Networking.Client diff --git a/JL.Core/Mining/Anki/AnkiUtils.cs b/JL.Core/Mining/Anki/AnkiUtils.cs index fe0265d3..be80d6c7 100644 --- a/JL.Core/Mining/Anki/AnkiUtils.cs +++ b/JL.Core/Mining/Anki/AnkiUtils.cs @@ -11,7 +11,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jso) : null; } @@ -21,7 +21,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jso) : null; } @@ -31,7 +31,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jso) : null; } @@ -41,7 +41,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize(resultString.AsSpan()[1..^1], Utils.s_jsoNotIgnoringNull) + ? JsonSerializer.Deserialize(resultString.AsSpan()[1..^1], Utils.s_jso) : null; } @@ -51,7 +51,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jso) : null; } } diff --git a/JL.Core/Utilities/Utils.cs b/JL.Core/Utilities/Utils.cs index 4e9d0560..dcaae6f0 100644 --- a/JL.Core/Utilities/Utils.cs +++ b/JL.Core/Utilities/Utils.cs @@ -49,14 +49,14 @@ public static partial class Utils shared: true) .CreateLogger(); - internal static readonly JsonSerializerOptions s_jsoNotIgnoringNull = new() + internal static readonly JsonSerializerOptions s_jso = new() { RespectNullableAnnotations = true, RespectRequiredConstructorParameters = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; - internal static readonly JsonSerializerOptions s_jsoIgnoringNull = new() + internal static readonly JsonSerializerOptions s_jsoIgnoringWhenWritingNull = new() { RespectNullableAnnotations = true, RespectRequiredConstructorParameters = true, @@ -64,7 +64,7 @@ public static partial class Utils DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; - internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverter = new() + internal static readonly JsonSerializerOptions s_jsoWithEnumConverter = new() { RespectNullableAnnotations = true, RespectRequiredConstructorParameters = true, @@ -75,19 +75,19 @@ public static partial class Utils } }; - internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverter = new() - { - RespectNullableAnnotations = true, - RespectRequiredConstructorParameters = true, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - Converters = - { - new JsonStringEnumConverter() - } - }; - - internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverterAndIndentation = new() + //internal static readonly JsonSerializerOptions s_jsoIgnoringWhenWritingNullWithEnumConverter = new() + //{ + // RespectNullableAnnotations = true, + // RespectRequiredConstructorParameters = true, + // Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + // DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + // Converters = + // { + // new JsonStringEnumConverter() + // } + //}; + + internal static readonly JsonSerializerOptions s_jsoWithEnumConverterAndIndentation = new() { RespectNullableAnnotations = true, RespectRequiredConstructorParameters = true, @@ -99,7 +99,7 @@ public static partial class Utils } }; - internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverterAndIndentation = new() + internal static readonly JsonSerializerOptions s_jsoIgnoringWhenWritingNullWithEnumConverterAndIndentation = new() { RespectNullableAnnotations = true, RespectRequiredConstructorParameters = true, diff --git a/JL.Core/WordClass/JmdictWordClassUtils.cs b/JL.Core/WordClass/JmdictWordClassUtils.cs index 51de202e..ab6945e8 100644 --- a/JL.Core/WordClass/JmdictWordClassUtils.cs +++ b/JL.Core/WordClass/JmdictWordClassUtils.cs @@ -13,7 +13,7 @@ public static async Task Load() FileStream fileStream = File.OpenRead(Path.Join(Utils.ResourcesPath, "PoS.json")); await using (fileStream.ConfigureAwait(false)) { - DictUtils.WordClassDictionary = (await JsonSerializer.DeserializeAsync>>(fileStream, Utils.s_jsoIgnoringNull).ConfigureAwait(false))!; + DictUtils.WordClassDictionary = (await JsonSerializer.DeserializeAsync>>(fileStream, Utils.s_jso).ConfigureAwait(false))!; } foreach (IList jmdictWordClassList in DictUtils.WordClassDictionary.Values.ToArray()) @@ -100,7 +100,7 @@ public static Task Serialize() } return File.WriteAllTextAsync(Path.Join(Utils.ResourcesPath, "PoS.json"), - JsonSerializer.Serialize(jmdictWordClassDictionary, Utils.s_jsoIgnoringNull)); + JsonSerializer.Serialize(jmdictWordClassDictionary, Utils.s_jsoIgnoringWhenWritingNull)); } internal static async Task Initialize()