From 343abd5fbf0d9848e754384af59b6cb1c72b1cb9 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 12 Feb 2024 15:17:46 +0100 Subject: [PATCH] Core,Tests: replace Newtonsoft.Json with STJ Replace Newtonsoft.Json with System.Text.Json so that we don't have different libraries for JSON, because System.Text.Json will be used by GRPC services. --- Directory.Packages.props | 2 +- src/FX.Core/FX.Core.fsproj | 2 +- src/FX.Core/RedisStorageLayer.fs | 20 ++++++++++++-------- src/FX.Tests/FX.Tests.csproj | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e51e66d..ee124af 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,7 +4,6 @@ - @@ -12,6 +11,7 @@ + diff --git a/src/FX.Core/FX.Core.fsproj b/src/FX.Core/FX.Core.fsproj index b1da1f4..65d63ec 100644 --- a/src/FX.Core/FX.Core.fsproj +++ b/src/FX.Core/FX.Core.fsproj @@ -13,6 +13,6 @@ - + diff --git a/src/FX.Core/RedisStorageLayer.fs b/src/FX.Core/RedisStorageLayer.fs index bedd39e..00e03de 100644 --- a/src/FX.Core/RedisStorageLayer.fs +++ b/src/FX.Core/RedisStorageLayer.fs @@ -5,9 +5,13 @@ open System open FsharpExchangeDotNetStandard -open Newtonsoft.Json +open System.Text.Json open StackExchange.Redis +[] +module Serialization = + let serializationOptions = JsonSerializerOptions.Default + type OrderQuery = { OrderId: string; @@ -26,9 +30,9 @@ type Query = type OrderBookSide(market: Market, side: Side) = let tipQuery = { Market = market; Tip = true; Side = side } - let tipQueryStr = JsonConvert.SerializeObject tipQuery + let tipQueryStr = JsonSerializer.Serialize(tipQuery, serializationOptions) let tailQuery = { Market = market; Tip = false; Side = side } - let tailQueryStr = JsonConvert.SerializeObject tailQuery + let tailQueryStr = JsonSerializer.Serialize(tailQuery, serializationOptions) member __.TipQuery = tipQueryStr member __.TailQuery = tailQueryStr @@ -53,7 +57,7 @@ module OrderRedisManager = db.CreateTransaction() let InsertOrder (limitOrder: LimitOrder): unit = - let serializedOrder = JsonConvert.SerializeObject limitOrder + let serializedOrder = JsonSerializer.Serialize(limitOrder, serializationOptions) let success = db.StringSet(RedisKey.op_Implicit (limitOrder.OrderInfo.Id.ToString()), RedisValue.op_Implicit (serializedOrder)) if not success then @@ -89,7 +93,7 @@ module OrderRedisManager = let orderSerialized = db.StringGet (RedisKey.op_Implicit tipOrderGuid) if not orderSerialized.HasValue then failwithf "Something went wrong, order tip was %s but was not found" tipOrderGuid - let tipOrder = JsonConvert.DeserializeObject (orderSerialized.ToString()) + let tipOrder = JsonSerializer.Deserialize(orderSerialized.ToString(), serializationOptions) tipOrder |> Some let private GetOrderSerialized (guidStr: string): Option = @@ -111,7 +115,7 @@ module OrderRedisManager = match maybeOrderSerialized with | None -> None | Some orderSerialized -> - let order = JsonConvert.DeserializeObject (orderSerialized.ToString()) + let order = JsonSerializer.Deserialize(orderSerialized.ToString(), serializationOptions) order |> Some let GetOrderByGuid (guid: Guid): Option = @@ -122,13 +126,13 @@ module OrderRedisManager = if not tail.HasValue then List.empty else - JsonConvert.DeserializeObject> (tail.ToString()) + JsonSerializer.Deserialize>(tail.ToString(), serializationOptions) let SetTail (transaction: StackExchange.Redis.ITransaction) (limitOrderGuids: List) (orderBookSide: OrderBookSide) : unit = - let serializedGuids = JsonConvert.SerializeObject limitOrderGuids + let serializedGuids = JsonSerializer.Serialize(limitOrderGuids, serializationOptions) transaction.StringSetAsync(RedisKey.op_Implicit orderBookSide.TailQuery, RedisValue.op_Implicit serializedGuids) |> ignore diff --git a/src/FX.Tests/FX.Tests.csproj b/src/FX.Tests/FX.Tests.csproj index 7bef3f5..0a2ee99 100644 --- a/src/FX.Tests/FX.Tests.csproj +++ b/src/FX.Tests/FX.Tests.csproj @@ -9,8 +9,8 @@ - +