From d632e52af0ef36d80d1dc0ebfd606bb1274e988c Mon Sep 17 00:00:00 2001 From: rampaa Date: Sat, 12 Oct 2024 07:22:21 +0300 Subject: [PATCH] Minor --- JL.Core/Audio/AudioUtils.cs | 6 ++-- JL.Core/Config/StatsDBUtils.cs | 6 ++-- JL.Core/Deconjugation/DeconjugatorUtils.cs | 2 +- JL.Core/Dicts/DictUtils.cs | 6 ++-- .../EPWING/Nazeka/EpwingNazekaDBManager.cs | 14 ++++----- .../Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs | 3 +- .../Yomichan/EpwingYomichanDBManager.cs | 14 ++++----- JL.Core/Dicts/JMdict/JmdictDBManager.cs | 22 +++++++------- JL.Core/Dicts/JMnedict/JmnedictDBManager.cs | 16 +++++----- JL.Core/Dicts/KANJIDIC/KanjidicDBManager.cs | 20 ++++++------- .../Dicts/KanjiDict/YomichanKanjiDBManager.cs | 16 +++++----- .../Dicts/KanjiDict/YomichanKanjiLoader.cs | 2 +- .../YomichanPitchAccentDBManager.cs | 2 +- .../PitchAccent/YomichanPitchAccentLoader.cs | 3 +- JL.Core/Freqs/FreqDBManager.cs | 2 +- JL.Core/Freqs/FreqUtils.cs | 6 ++-- .../FrequencyNazeka/FrequencyNazekaLoader.cs | 3 +- .../FrequencyYomichanLoader.cs | 3 +- JL.Core/Mining/Anki/AnkiConfig.cs | 4 +-- JL.Core/Mining/Anki/AnkiConnect.cs | 2 +- JL.Core/Mining/Anki/AnkiUtils.cs | 7 +++-- JL.Core/Utilities/Utils.cs | 29 +++++++++++++++---- JL.Core/WordClass/JmdictWordClassUtils.cs | 4 +-- 23 files changed, 107 insertions(+), 85 deletions(-) diff --git a/JL.Core/Audio/AudioUtils.cs b/JL.Core/Audio/AudioUtils.cs index e0053d10..95eae1af 100644 --- a/JL.Core/Audio/AudioUtils.cs +++ b/JL.Core/Audio/AudioUtils.cs @@ -200,14 +200,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_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(AudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } public static Task CreateDefaultAudioSourceConfig() { _ = Directory.CreateDirectory(Utils.ConfigPath); return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "AudioSourceConfig.json"), - JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(s_builtInAudioSources, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } internal static async Task DeserializeAudioSources() @@ -216,7 +216,7 @@ internal static async Task DeserializeAudioSources() await using (fileStream.ConfigureAwait(false)) { Dictionary? deserializedAudioSources = await JsonSerializer - .DeserializeAsync>(fileStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); if (deserializedAudioSources is not null) { diff --git a/JL.Core/Config/StatsDBUtils.cs b/JL.Core/Config/StatsDBUtils.cs index 84779ce0..677ec3c7 100644 --- a/JL.Core/Config/StatsDBUtils.cs +++ b/JL.Core/Config/StatsDBUtils.cs @@ -9,7 +9,7 @@ public static class StatsDBUtils { public static void InsertStats(SqliteConnection connection, Stats stats, int profileId) { - InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId); + InsertStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId); } public static void InsertStats(SqliteConnection connection, string stats, int profileId) @@ -28,7 +28,7 @@ INSERT INTO stats (profile_id, value) private static void UpdateStats(SqliteConnection connection, Stats stats, int profileId) { - UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoWithEnumConverterAndIndentation), profileId); + UpdateStats(connection, JsonSerializer.Serialize(stats, Utils.s_jsoNotIgnoringNullWithEnumConverterAndIndentation), profileId); } public static void UpdateStats(SqliteConnection connection, string stats, int profileId) @@ -61,7 +61,7 @@ FROM stats string? statsValue = (string?)command.ExecuteScalar(); return statsValue is not null - ? JsonSerializer.Deserialize(statsValue, Utils.s_jsoWithEnumConverter) + ? JsonSerializer.Deserialize(statsValue, Utils.s_jsoNotIgnoringNullWithEnumConverter) : null; } diff --git a/JL.Core/Deconjugation/DeconjugatorUtils.cs b/JL.Core/Deconjugation/DeconjugatorUtils.cs index 861dd929..453d814c 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_defaultJso).ConfigureAwait(false))!; + Deconjugator.Rules = (await JsonSerializer.DeserializeAsync(fileStream, Utils.s_jsoNotIgnoringNull).ConfigureAwait(false))!; } for (int i = 0; i < Deconjugator.Rules.Length; i++) diff --git a/JL.Core/Dicts/DictUtils.cs b/JL.Core/Dicts/DictUtils.cs index 1abad60c..9a40e095 100644 --- a/JL.Core/Dicts/DictUtils.cs +++ b/JL.Core/Dicts/DictUtils.cs @@ -1375,13 +1375,13 @@ public static Task CreateDefaultDictsConfig() { _ = Directory.CreateDirectory(Utils.ConfigPath); return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"), - JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(BuiltInDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } public static Task SerializeDicts() { return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "dicts.json"), - JsonSerializer.Serialize(Dicts, Utils.s_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(Dicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } internal static async Task DeserializeDicts() @@ -1390,7 +1390,7 @@ internal static async Task DeserializeDicts() await using (dictStream.ConfigureAwait(false)) { Dictionary? deserializedDicts = await JsonSerializer - .DeserializeAsync>(dictStream, Utils.s_jsoWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(dictStream, Utils.s_jsoIgnoringNullWithEnumConverter).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 0809d50f..80be4708 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_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_defaultJso); + _ = 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.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_defaultJso); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); } - string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; if (results.TryGetValue(searchKey, out IList? result)) { @@ -234,7 +234,7 @@ FROM record r while (dataReader.Read()) { EpwingNazekaRecord record = GetRecord(dataReader); - string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!; + string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; for (int i = 0; i < searchKeys.Length; 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_defaultJso); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); } - string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; 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 b19bc063..c5931ed5 100644 --- a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs +++ b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs @@ -20,8 +20,7 @@ public static async Task Load(Dict dict) FileStream fileStream = File.OpenRead(fullPath); await using (fileStream.ConfigureAwait(false)) { - jsonObjects = await JsonSerializer.DeserializeAsync>(fileStream) - .ConfigureAwait(false); + jsonObjects = await JsonSerializer.DeserializeAsync>(fileStream, Utils.s_jsoNotIgnoringNull).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 c381f801..3639d38c 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_defaultJso); - _ = insertRecordCommand.Parameters["@part_of_speech"].Value = record.WordClasses is not null ? JsonSerializer.Serialize(record.WordClasses, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary_tags"].Value = record.DefinitionTags is not null ? JsonSerializer.Serialize(record.DefinitionTags, Utils.s_defaultJso) : 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.ExecuteNonQuery(); _ = insertSearchKeyCommand.Parameters["@record_id"].Value = id; @@ -221,7 +221,7 @@ FROM record r while (dataReader.Read()) { EpwingYomichanRecord record = GetRecord(dataReader); - string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!; + string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; for (int i = 0; i < searchKeys.Length; 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_defaultJso)!; + string[] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; string[]? wordClasses = null; if (dataReader[nameof(wordClasses)] is string wordClassesFromDB) { - wordClasses = JsonSerializer.Deserialize(wordClassesFromDB, Utils.s_defaultJso); + wordClasses = JsonSerializer.Deserialize(wordClassesFromDB, Utils.s_jsoNotIgnoringNull); } string[]? definitionTags = null; if (dataReader[nameof(definitionTags)] is string definitionTagsFromDB) { - definitionTags = JsonSerializer.Deserialize(definitionTagsFromDB, Utils.s_defaultJso); + definitionTags = JsonSerializer.Deserialize(definitionTagsFromDB, Utils.s_jsoNotIgnoringNull); } 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 ea4a556b..ca3b92ab 100644 --- a/JL.Core/Dicts/JMdict/JmdictDBManager.cs +++ b/JL.Core/Dicts/JMdict/JmdictDBManager.cs @@ -127,15 +127,15 @@ 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_defaultJso) : DBNull.Value; - insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_defaultJso) : DBNull.Value; + 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_defaultJso) : 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_defaultJso); + 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_defaultJso); + 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; @@ -272,7 +272,7 @@ FROM record r { JmdictRecord record = GetRecord(dataReader); - string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!; + string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; for (int i = 0; i < searchKeys.Length; i++) { string searchKey = searchKeys[i]; @@ -303,7 +303,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader) string[]? primarySpellingOrthographyInfo = null; if (dataReader[nameof(primarySpellingOrthographyInfo)] is string primarySpellingOrthographyInfoFromDB) { - primarySpellingOrthographyInfo = JsonSerializer.Deserialize(primarySpellingOrthographyInfoFromDB, Utils.s_defaultJso); + primarySpellingOrthographyInfo = JsonSerializer.Deserialize(primarySpellingOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull); } string[]?[]? spellingRestrictions = null; @@ -315,7 +315,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader) string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_defaultJso); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]?[]? alternativeSpellingsOrthographyInfo = null; @@ -327,7 +327,7 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader) string[]? readings = null; if (dataReader[nameof(readings)] is string readingsFromDB) { - readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_defaultJso); + readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]?[]? readingRestrictions = null; @@ -342,8 +342,8 @@ private static JmdictRecord GetRecord(SqliteDataReader dataReader) readingsOrthographyInfo = JsonSerializer.Deserialize(readingsOrthographyInfoFromDB, Utils.s_jsoNotIgnoringNull); } - string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!; - string[][] wordClasses = JsonSerializer.Deserialize(dataReader.GetString(nameof(wordClasses)), Utils.s_defaultJso)!; + string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; + string[][] wordClasses = JsonSerializer.Deserialize(dataReader.GetString(nameof(wordClasses)), Utils.s_jsoNotIgnoringNull)!; string[]?[]? fields = null; if (dataReader[nameof(fields)] is string fieldsFromDB) diff --git a/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs b/JL.Core/Dicts/JMnedict/JmnedictDBManager.cs index 4761465d..040bab63 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_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@alternative_spellings"].Value = record.AlternativeSpellings is not null ? JsonSerializer.Serialize(record.AlternativeSpellings, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = JsonSerializer.Serialize(record.Definitions, Utils.s_defaultJso); - _ = insertRecordCommand.Parameters["@name_types"].Value = JsonSerializer.Serialize(record.NameTypes, Utils.s_defaultJso); + _ = 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.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_defaultJso); + readings = JsonSerializer.Deserialize(readingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? alternativeSpellings = null; if (dataReader[nameof(alternativeSpellings)] is string alternativeSpellingsFromDB) { - alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_defaultJso); + alternativeSpellings = JsonSerializer.Deserialize(alternativeSpellingsFromDB, Utils.s_jsoNotIgnoringNull); } - string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_defaultJso)!; - string[][] nameTypes = JsonSerializer.Deserialize(dataReader.GetString(nameof(nameTypes)), Utils.s_defaultJso)!; + string[][] definitions = JsonSerializer.Deserialize(dataReader.GetString(nameof(definitions)), Utils.s_jsoNotIgnoringNull)!; + string[][] nameTypes = JsonSerializer.Deserialize(dataReader.GetString(nameof(nameTypes)), Utils.s_jsoNotIgnoringNull)!; 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 0c683962..4209544b 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_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@kun_readings"].Value = kanjidicRecord.KunReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.KunReadings, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@nanori_readings"].Value = kanjidicRecord.NanoriReadings is not null ? JsonSerializer.Serialize(kanjidicRecord.NanoriReadings, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@radical_names"].Value = kanjidicRecord.RadicalNames is not null ? JsonSerializer.Serialize(kanjidicRecord.RadicalNames, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = kanjidicRecord.Definitions is not null ? JsonSerializer.Serialize(kanjidicRecord.Definitions, Utils.s_defaultJso) : DBNull.Value; + _ = 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["@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_defaultJso); + onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? kunReadings = null; if (dataReader[nameof(kunReadings)] is string kunReadingsFromDB) { - kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_defaultJso); + kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? nanoriReadings = null; if (dataReader[nameof(nanoriReadings)] is string nanoriReadingsFromDB) { - nanoriReadings = JsonSerializer.Deserialize(nanoriReadingsFromDB, Utils.s_defaultJso); + nanoriReadings = JsonSerializer.Deserialize(nanoriReadingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? radicalNames = null; if (dataReader[nameof(radicalNames)] is string radicalNamesFromDB) { - radicalNames = JsonSerializer.Deserialize(radicalNamesFromDB, Utils.s_defaultJso); + radicalNames = JsonSerializer.Deserialize(radicalNamesFromDB, Utils.s_jsoNotIgnoringNull); } string[]? definitions = null; if (dataReader[nameof(definitions)] is string definitionsFromDB) { - definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_defaultJso); + definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jsoNotIgnoringNull); } byte strokeCount = dataReader.GetByte(nameof(strokeCount)); diff --git a/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs b/JL.Core/Dicts/KanjiDict/YomichanKanjiDBManager.cs index bd40d651..ab99a9fa 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_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@kun_readings"].Value = yomichanKanjiRecord.KunReadings is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.KunReadings, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@glossary"].Value = yomichanKanjiRecord.Definitions is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Definitions, Utils.s_defaultJso) : DBNull.Value; - _ = insertRecordCommand.Parameters["@stats"].Value = yomichanKanjiRecord.Stats is not null ? JsonSerializer.Serialize(yomichanKanjiRecord.Stats, Utils.s_defaultJso) : DBNull.Value; + _ = 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.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_defaultJso); + onReadings = JsonSerializer.Deserialize(onReadingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? kunReadings = null; if (dataReader[nameof(kunReadings)] is string kunReadingsFromDB) { - kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_defaultJso); + kunReadings = JsonSerializer.Deserialize(kunReadingsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? definitions = null; if (dataReader[nameof(definitions)] is string definitionsFromDB) { - definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_defaultJso); + definitions = JsonSerializer.Deserialize(definitionsFromDB, Utils.s_jsoNotIgnoringNull); } string[]? stats = null; if (dataReader[nameof(stats)] is string statsFromDB) { - stats = JsonSerializer.Deserialize(statsFromDB, Utils.s_defaultJso); + stats = JsonSerializer.Deserialize(statsFromDB, Utils.s_jsoNotIgnoringNull); } return new YomichanKanjiRecord(onReadings, kunReadings, definitions, stats); diff --git a/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs b/JL.Core/Dicts/KanjiDict/YomichanKanjiLoader.cs index 5486fdf1..b274d727 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) + .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) .ConfigureAwait(false); } diff --git a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentDBManager.cs index adb49cc4..03aa58ed 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); - string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!; + string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; for (int i = 0; i < searchKeys.Length; i++) { string searchKey = searchKeys[i]; diff --git a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs index c71b8f2b..4ecaebcd 100644 --- a/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs +++ b/JL.Core/Dicts/PitchAccent/YomichanPitchAccentLoader.cs @@ -24,7 +24,8 @@ public static async Task Load(Dict dict) FileStream fileStream = File.OpenRead(jsonFile); await using (fileStream.ConfigureAwait(false)) { - jsonObjects = await JsonSerializer.DeserializeAsync>>(fileStream) + jsonObjects = await JsonSerializer + .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) .ConfigureAwait(false); } diff --git a/JL.Core/Freqs/FreqDBManager.cs b/JL.Core/Freqs/FreqDBManager.cs index 94be20d1..2e0276d3 100644 --- a/JL.Core/Freqs/FreqDBManager.cs +++ b/JL.Core/Freqs/FreqDBManager.cs @@ -227,7 +227,7 @@ FROM record r { FrequencyRecord record = GetRecord(dataReader); - string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_defaultJso)!; + string[] searchKeys = JsonSerializer.Deserialize(dataReader.GetString(nameof(searchKeys)), Utils.s_jsoNotIgnoringNull)!; for (int i = 0; i < searchKeys.Length; i++) { string searchKey = searchKeys[i]; diff --git a/JL.Core/Freqs/FreqUtils.cs b/JL.Core/Freqs/FreqUtils.cs index 66ad5e2c..c58a1d14 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_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(s_builtInFreqs, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } public static Task SerializeFreqs() { return File.WriteAllTextAsync(Path.Join(Utils.ConfigPath, "freqs.json"), - JsonSerializer.Serialize(FreqDicts, Utils.s_jsoWithEnumConverterAndIndentation)); + JsonSerializer.Serialize(FreqDicts, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)); } 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_jsoWithEnumConverter).ConfigureAwait(false); + .DeserializeAsync>(fileStream, Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); if (deserializedFreqs is not null) { diff --git a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs index e26056d9..cf6a204e 100644 --- a/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs +++ b/JL.Core/Freqs/FrequencyNazeka/FrequencyNazekaLoader.cs @@ -19,7 +19,8 @@ public static async Task Load(Freq freq) FileStream fileStream = File.OpenRead(fullPath); await using (fileStream.ConfigureAwait(false)) { - frequencyJson = await JsonSerializer.DeserializeAsync>>>(fileStream) + frequencyJson = await JsonSerializer + .DeserializeAsync>>>(fileStream, Utils.s_jsoNotIgnoringNull) .ConfigureAwait(false); } diff --git a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs index 92db1af0..dc968288 100644 --- a/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs +++ b/JL.Core/Freqs/FrequencyYomichan/FrequencyYomichanLoader.cs @@ -24,7 +24,8 @@ public static async Task Load(Freq freq) FileStream fileStream = File.OpenRead(jsonFile); await using (fileStream.ConfigureAwait(false)) { - frequencyJson = await JsonSerializer.DeserializeAsync>>(fileStream) + frequencyJson = await JsonSerializer + .DeserializeAsync>>(fileStream, Utils.s_jsoNotIgnoringNull) .ConfigureAwait(false); } diff --git a/JL.Core/Mining/Anki/AnkiConfig.cs b/JL.Core/Mining/Anki/AnkiConfig.cs index 00f11b8d..111b6ad4 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_jsoWithEnumConverterAndIndentation)).ConfigureAwait(false); + JsonSerializer.Serialize(ankiConfig, Utils.s_jsoIgnoringNullWithEnumConverterAndIndentation)).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_jsoWithEnumConverter).ConfigureAwait(false); + Utils.s_jsoIgnoringNullWithEnumConverter).ConfigureAwait(false); } } diff --git a/JL.Core/Mining/Anki/AnkiConnect.cs b/JL.Core/Mining/Anki/AnkiConnect.cs index 3437d206..5d67eb8b 100644 --- a/JL.Core/Mining/Anki/AnkiConnect.cs +++ b/JL.Core/Mining/Anki/AnkiConnect.cs @@ -75,7 +75,7 @@ public static async Task Sync() try { // AnkiConnect doesn't like null values - using StringContent payload = new(JsonSerializer.Serialize(req, Utils.s_defaultJso)); + using StringContent payload = new(JsonSerializer.Serialize(req, Utils.s_jsoIgnoringNull)); 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 def7a842..1043e864 100644 --- a/JL.Core/Mining/Anki/AnkiUtils.cs +++ b/JL.Core/Mining/Anki/AnkiUtils.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using JL.Core.Utilities; namespace JL.Core.Mining.Anki; @@ -10,7 +11,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) : null; } @@ -20,7 +21,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) : null; } @@ -30,7 +31,7 @@ public static class AnkiUtils string? resultString = response?.Result?.ToString() ?? null; return resultString is not null - ? JsonSerializer.Deserialize>(resultString) + ? JsonSerializer.Deserialize>(resultString, Utils.s_jsoNotIgnoringNull) : null; } diff --git a/JL.Core/Utilities/Utils.cs b/JL.Core/Utilities/Utils.cs index 754e3875..0a0d44d5 100644 --- a/JL.Core/Utilities/Utils.cs +++ b/JL.Core/Utilities/Utils.cs @@ -48,13 +48,27 @@ public static partial class Utils shared: true) .CreateLogger(); - internal static readonly JsonSerializerOptions s_defaultJso = new() + internal static readonly JsonSerializerOptions s_jsoNotIgnoringNull = new() + { + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + }; + + internal static readonly JsonSerializerOptions s_jsoIgnoringNull = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; - internal static readonly JsonSerializerOptions s_jsoWithEnumConverter = new() + internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverter = new() + { + Converters = + { + new JsonStringEnumConverter() + }, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }; + + internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverter = new() { Converters = { @@ -64,12 +78,17 @@ public static partial class Utils DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; - internal static readonly JsonSerializerOptions s_jsoNotIgnoringNull = new() + internal static readonly JsonSerializerOptions s_jsoNotIgnoringNullWithEnumConverterAndIndentation = new() { - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + Converters = + { + new JsonStringEnumConverter() + }, + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + WriteIndented = true }; - internal static readonly JsonSerializerOptions s_jsoWithEnumConverterAndIndentation = new() + internal static readonly JsonSerializerOptions s_jsoIgnoringNullWithEnumConverterAndIndentation = new() { Converters = { diff --git a/JL.Core/WordClass/JmdictWordClassUtils.cs b/JL.Core/WordClass/JmdictWordClassUtils.cs index d2a65d77..410d3494 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).ConfigureAwait(false))!; + DictUtils.WordClassDictionary = (await JsonSerializer.DeserializeAsync>>(fileStream, Utils.s_jsoIgnoringNull).ConfigureAwait(false))!; } foreach (IList jmdictWordClassList in DictUtils.WordClassDictionary.Values.ToList()) @@ -100,7 +100,7 @@ public static Task Serialize() } return File.WriteAllTextAsync(Path.Join(Utils.ResourcesPath, "PoS.json"), - JsonSerializer.Serialize(jmdictWordClassDictionary, Utils.s_defaultJso)); + JsonSerializer.Serialize(jmdictWordClassDictionary, Utils.s_jsoIgnoringNull)); } internal static async Task Initialize()