Skip to content

Commit

Permalink
Support route deserialization from object to array in case of route l…
Browse files Browse the repository at this point in the history
…ist query with routeID. As a result, list with 1 element is returned as result.
  • Loading branch information
Dmitry Koval authored and Dmitry Koval committed Jan 13, 2023
1 parent 6868a9e commit 24d19be
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion route4me-csharp-sdk/Route4MeSDKLibrary/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@ public static T ReadObjectNew<T>(this Stream stream)
}
}

if (typeof(T) == typeof(DataTypes.V5.DataObjectRoute[]))
{
try
{
return JsonConvert.DeserializeObject<T>(text, jsonSettings);
}

catch (JsonSerializationException)
{
DataTypes.V5.DataObjectRoute internalResponse = (DataTypes.V5.DataObjectRoute)JsonConvert.DeserializeObject(text, typeof(DataTypes.V5.DataObjectRoute));
var externalResponse = new[] { internalResponse };

text = JsonConvert.SerializeObject(externalResponse);
}
}

if (typeof(T) == typeof(Route4MeSDK.DataTypes.DataObjectRoute[]))
{
try
{
return JsonConvert.DeserializeObject<T>(text, jsonSettings);
}

catch (JsonSerializationException)
{
DataTypes.DataObjectRoute internalResponse = (DataTypes.DataObjectRoute)JsonConvert.DeserializeObject(text, typeof(DataTypes.DataObjectRoute));
var externalResponse = new[] { internalResponse };

text = JsonConvert.SerializeObject(externalResponse);
}
}

//if (typeof(T) == typeof(DataTypes.V5.ArchiveOrdersResponse))
//{
// var pattern = string.Concat(
Expand All @@ -147,7 +179,7 @@ public static T ReadObjectNew<T>(this Stream stream)
// var map = new Dictionary<string, string>()
// {
// {pattern,pattern2}

// };

// rgx = new Regex(pattern);
Expand Down

0 comments on commit 24d19be

Please sign in to comment.