Skip to content

Commit 97fb16a

Browse files
committed
Changes to move away from Newtonsoft. Apparently, there is a JsonNode object that can replace the ExpandoObject approach used with Json.net.
1 parent fe64a12 commit 97fb16a

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

ClassLibrary/DataWarehouseAutomation/DataWarehouseAutomation/HandleBarsHelpers.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,19 @@ public static void RegisterHandleBarsHelpers()
216216
{
217217
try
218218
{
219-
string expression = args[0] as string;
219+
var expression = args[0];
220220

221-
if (args[0] is System.Text.Json.JsonElement value)
221+
var bla = "";
222+
223+
if (!String.IsNullOrEmpty(expression.ToString()) && args[0] is System.Text.Json.JsonElement value)
222224
{
223225
expression = value.GetString();
224226
}
225227

226228
string pattern = args[1] as string;
227229
string replacement = args[2] as string;
228230

229-
expression = expression.Replace(pattern, replacement);
231+
expression = expression.ToString().Replace(pattern, replacement);
230232
writer.WriteSafeString(expression);
231233
}
232234
catch (Exception exception)

ClassLibrary/DataWarehouseAutomation/Example_Project/Examples.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</ItemGroup>
1212
<ItemGroup>
1313
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
14-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1514
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
1615
</ItemGroup>
1716
</Project>

ClassLibrary/DataWarehouseAutomation/Example_Project/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
2-
using System.Dynamic;
32
using System.IO;
43
using DataWarehouseAutomation;
54
using HandlebarsDotNet;
6-
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Converters;
5+
using System.Text.Json.Nodes;
86

97
namespace Example_Handlebars
108
{
@@ -40,7 +38,10 @@ private static void DisplayPatternResult(string patternFile, string jsonMetadata
4038
// Fetch the content of the Json files
4139
string jsonInput = File.ReadAllText(jsonMetadataFile);
4240

43-
var deserialisedMapping = JsonConvert.DeserializeObject<ExpandoObject>(jsonInput, new ExpandoObjectConverter());
41+
//ar deserialisedMapping = JsonConvert.DeserializeObject<ExpandoObject>(jsonInput, new ExpandoObjectConverter()); -- This is the old Newtonsoft expando object approach
42+
//var deserialisedMapping = System.Text.Json.JsonSerializer.Deserialize<ExpandoObject>(jsonInput);
43+
44+
JsonNode deserialisedMapping = System.Text.Json.JsonSerializer.Deserialize<JsonNode>(jsonInput);
4445

4546
var result = template(deserialisedMapping);
4647
Console.WriteLine(result);

ClassLibrary/DataWarehouseAutomation/RunDwhAutomation/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ static int Main(string[] args)
1414
// An optimistic start.
1515
Environment.ExitCode = (int)ExitCode.Success;
1616

17+
// Get the handlebars extensions from the DataWarehouseAutomation class library.
1718
HandleBarsHelpers.RegisterHandleBarsHelpers();
1819

1920
#region unit testing
@@ -116,7 +117,7 @@ static int Main(string[] args)
116117
{
117118
if (options.outputFileName == null)
118119
{
119-
// The outputfilename will be derived from the Json input (mappingName), if available.
120+
// The output filename will be derived from the Json input (mappingName), if available.
120121
RunAutomation(options, file);
121122
}
122123
else

ClassLibrary/DataWarehouseAutomation/Sample_Metadata/sampleFreeForm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sourceApp": {
3-
"value": "abs-event-service",
4-
"description": "name of source system."
3+
"value": "event-service",
4+
"description": "name of system"
55
},
66
"topicName": {
77
"value": "application-declined"

ClassLibrary/DataWarehouseAutomation/Sample_Templates/TemplateSampleFreeForm.Handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"bucketrootpath": "kafka/topics",
44
"container": "{{sourceApp.value}}",
55
"containerrootpath": "data",
6-
"module_code": "m_050_kafka_{{StringReplace topicName.value '-' '_'}}"
6+
"module_code": "kafka_{{StringReplace topicName.value '-' '_'}}"
77
}
88

0 commit comments

Comments
 (0)