-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
|
||
namespace GitVersionExe.Tests.Helpers | ||
{ | ||
public class CustomJsonSerializer | ||
{ | ||
public static T Deserialize<T>(string json) | ||
{ | ||
var data = JsonSerializer.Deserialize<T>(json); | ||
|
||
if (data is Dictionary<string, object> odata) | ||
{ | ||
var ndata = new Dictionary<string, object>(); | ||
foreach (var key in odata.Keys) | ||
{ | ||
var value = (JsonElement)odata[key]; | ||
switch (value.ValueKind) | ||
{ | ||
case JsonValueKind.Undefined: | ||
break; | ||
case JsonValueKind.Object: | ||
break; | ||
case JsonValueKind.Array: | ||
break; | ||
case JsonValueKind.String: | ||
ndata.Add(key, value.GetString()); | ||
break; | ||
case JsonValueKind.Number: | ||
ndata.Add(key, value.GetInt64().ToString()); | ||
break; | ||
case JsonValueKind.True: | ||
break; | ||
case JsonValueKind.False: | ||
break; | ||
case JsonValueKind.Null: | ||
break; | ||
} | ||
} | ||
|
||
if (ndata is T obj) return obj; | ||
} | ||
|
||
return data; | ||
} | ||
} | ||
} |