Skip to content

Commit

Permalink
Core,Tests: replace Newtonsoft.Json with STJ
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
webwarrior-ws committed Feb 12, 2024
1 parent 33ce6fa commit 343abd5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="StackExchange.Redis" Version="2.0.513" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NUnit" Version="3.9.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageVersion Include="Microsoft.AspNetCore.App" Version="2.1.34" />
<PackageVersion Include="Giraffe" Version="3.1.0" />
<PackageVersion Include="Giraffe.Razor" Version="1.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.1" />
<PackageVersion Include="TaskBuilder.fs" Version="2.1.0" />
<PackageVersion Include="FSharp.Core" Version="8.0.101" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/FX.Core/FX.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
</Project>
20 changes: 12 additions & 8 deletions src/FX.Core/RedisStorageLayer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ open System

open FsharpExchangeDotNetStandard

open Newtonsoft.Json
open System.Text.Json
open StackExchange.Redis

[<AutoOpen>]
module Serialization =
let serializationOptions = JsonSerializerOptions.Default

type OrderQuery =
{
OrderId: string;
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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<LimitOrder> (orderSerialized.ToString())
let tipOrder = JsonSerializer.Deserialize<LimitOrder>(orderSerialized.ToString(), serializationOptions)
tipOrder |> Some

let private GetOrderSerialized (guidStr: string): Option<string> =
Expand All @@ -111,7 +115,7 @@ module OrderRedisManager =
match maybeOrderSerialized with
| None -> None
| Some orderSerialized ->
let order = JsonConvert.DeserializeObject<LimitOrder> (orderSerialized.ToString())
let order = JsonSerializer.Deserialize<LimitOrder>(orderSerialized.ToString(), serializationOptions)
order |> Some

let GetOrderByGuid (guid: Guid): Option<LimitOrder> =
Expand All @@ -122,13 +126,13 @@ module OrderRedisManager =
if not tail.HasValue then
List.empty
else
JsonConvert.DeserializeObject<List<string>> (tail.ToString())
JsonSerializer.Deserialize<List<string>>(tail.ToString(), serializationOptions)

let SetTail (transaction: StackExchange.Redis.ITransaction)
(limitOrderGuids: List<string>)
(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
Expand Down
2 changes: 1 addition & 1 deletion src/FX.Tests/FX.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="StackExchange.Redis" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="FSharp.Core" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Class1.cs" />
Expand Down

0 comments on commit 343abd5

Please sign in to comment.