From 4826fc92375b2286359b8198d034afa7d1aa6c71 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 23 Feb 2026 13:03:49 -0500 Subject: [PATCH] build: Remove dependency on Newtonsoft.Json (in DataStreamCore) Replace with System.Text.Json (official dotnet) --- .../BlueData/BlueDataUtility.cs | 5 ++-- .../DataStreamCore/BlueData/ColumnInfo.cs | 7 +++-- .../BlueData/ColumnInfoJsonConverter.cs | 27 +++++++++++++++++++ .../DataStreamCore/DataStreamCore.csproj | 1 - .../Historical/HistoricalBarsStream.cs | 2 -- 5 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfoJsonConverter.cs diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs index 3dc399eef..09f53b98e 100644 --- a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs +++ b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs @@ -15,7 +15,6 @@ using mbts; using BCG.Extensions; using System.Text.Json; using System.Text.Json.Nodes; -using Newtonsoft.Json; using BCG; using System.Runtime.CompilerServices; using bts; @@ -360,11 +359,11 @@ namespace BCG { } public static Dictionary convert_json_to_dictionary(string json_string) { - Dictionary dictionary = JsonConvert.DeserializeObject>(json_string); + Dictionary dictionary = JsonSerializer.Deserialize>(json_string); return dictionary; } public static IBlueRow convert_json_to_row(string json_string, int id = 0) { - Dictionary dictionary = JsonConvert.DeserializeObject>(json_string); + Dictionary dictionary = JsonSerializer.Deserialize>(json_string); if (!dictionary.ContainsKey("id")) { dictionary.Add("id", id); } diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfo.cs b/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfo.cs index fafe943ed..8b0f32d5e 100644 --- a/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfo.cs +++ b/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfo.cs @@ -1,4 +1,6 @@ #nullable enable +using Bts.DataStreamCore; + using System; using System.Text.Json.Serialization; @@ -7,6 +9,7 @@ namespace BCG { /// Resprsents information about a column schema, ie its ordinal, the type, the name and constant value or expression. where applicable /// [Serializable] + [JsonConverter(typeof(ColumnInfoJsonConverter))] public class ColumnInfo : IComparable, IComparable, IEquatable { //the default column info does not cach values in a lookup table, therefore it is in group 0 @@ -67,16 +70,12 @@ namespace BCG { private Type myColType; private object? myColValue; - [JsonPropertyName("colNo")] public int colNo { get { return myColNo; } } - [JsonPropertyName("colName")] public string colName { get { return myColName; } } - [JsonPropertyName("colType")] public Type colType { get { return myColType; } } - [JsonIgnore] public object? colValue {get{return myColValue;}} } } diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfoJsonConverter.cs b/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfoJsonConverter.cs new file mode 100644 index 000000000..47f1c29fa --- /dev/null +++ b/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfoJsonConverter.cs @@ -0,0 +1,27 @@ +namespace Bts.DataStreamCore; + +using BCG; + +using Spark.Core.Json; + +using System; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +public class ColumnInfoJsonConverter : JsonConverter { + public override ColumnInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { + var jobj = JsonSerializer.Deserialize(ref reader); + return new( + jobj[nameof(ColumnInfo.colName)].GetValue(), + jobj[nameof(ColumnInfo.colNo)].GetValue(), + Type.GetType(jobj[nameof(ColumnInfo.colType)].GetValue())); + } + + public override void Write(Utf8JsonWriter writer, ColumnInfo value, JsonSerializerOptions options) { + using var _ = writer.WriteObject(); + writer.WriteString(nameof(ColumnInfo.colName), value.colName); + writer.WriteNumber(nameof(ColumnInfo.colNo), value.colNo); + writer.WriteString(nameof(ColumnInfo.colType), value.colType.ToString()); + } +} diff --git a/src/DataStreamSuite/DataStreamCore/DataStreamCore.csproj b/src/DataStreamSuite/DataStreamCore/DataStreamCore.csproj index ae00da49c..59e6412d8 100644 --- a/src/DataStreamSuite/DataStreamCore/DataStreamCore.csproj +++ b/src/DataStreamSuite/DataStreamCore/DataStreamCore.csproj @@ -8,7 +8,6 @@ - diff --git a/src/DataStreamSuite/SharedStreams/BlueOrb/MarketData/Historical/HistoricalBarsStream.cs b/src/DataStreamSuite/SharedStreams/BlueOrb/MarketData/Historical/HistoricalBarsStream.cs index 4933ae193..072537264 100644 --- a/src/DataStreamSuite/SharedStreams/BlueOrb/MarketData/Historical/HistoricalBarsStream.cs +++ b/src/DataStreamSuite/SharedStreams/BlueOrb/MarketData/Historical/HistoricalBarsStream.cs @@ -215,8 +215,6 @@ namespace bts.BlueOrb { using bts.api; - using Newtonsoft.Json.Serialization; - [DataStreamUserRespresentation("FuturesContinousContract")] public class FuturesContinousContractStream : ViewStream { // the argument is symbol, like "ES" etc and not the contract itself