mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 12:32:03 -04:00
Add JsonSerializerOptions for serialization and deserialization (#70)
Add JsonSerializerOptions for serialization and deserialization apparently it has problems with lists with groups like my list<(int r, int c)> so needs options
This commit is contained in:
@@ -259,7 +259,8 @@ public class KasinoMines
|
|||||||
if (string.IsNullOrEmpty(json)) return;
|
if (string.IsNullOrEmpty(json)) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ActiveGames = JsonSerializer.Deserialize<Dictionary<int, KasinoMinesGame>>(json.ToString()) ??
|
var options = new JsonSerializerOptions{IncludeFields = true};
|
||||||
|
ActiveGames = JsonSerializer.Deserialize<Dictionary<int, KasinoMinesGame>>(json.ToString(), options) ??
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -272,7 +273,12 @@ public class KasinoMines
|
|||||||
public async Task SaveActiveGames(int gamblerId)
|
public async Task SaveActiveGames(int gamblerId)
|
||||||
{
|
{
|
||||||
if (_redisDb == null) throw new InvalidOperationException("Kasino mines service isn't initialized");
|
if (_redisDb == null) throw new InvalidOperationException("Kasino mines service isn't initialized");
|
||||||
var json = JsonSerializer.Serialize(ActiveGames);
|
var options = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
IncludeFields = true,
|
||||||
|
WriteIndented = false
|
||||||
|
};
|
||||||
|
var json = JsonSerializer.Serialize(ActiveGames, options);
|
||||||
await _redisDb.StringSetAsync($"Mines.State.{gamblerId}", json, null, When.Always);
|
await _redisDb.StringSetAsync($"Mines.State.{gamblerId}", json, null, When.Always);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user