Skip to content

Commit b1b1e2e

Browse files
authored
Fix deserialization bug (#46666)
1 parent 31289c4 commit b1b1e2e

File tree

5 files changed

+66
-45
lines changed

5 files changed

+66
-45
lines changed

sdk/maps/Azure.Maps.Routing/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/maps/Azure.Maps.Routing",
5-
"Tag": "net/maps/Azure.Maps.Routing_54064ae0c1"
5+
"Tag": "net/maps/Azure.Maps.Routing_0755b0a67d"
66
}

sdk/maps/Azure.Maps.Routing/src/Generated/Models/RouteMatrix.Serialization.cs

Lines changed: 0 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/maps/Azure.Maps.Routing/src/Models/Operation/GetRouteMatrixOperation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ private async ValueTask<Response<RouteMatrixResult>> WaitForCompletionAsync(bool
110110
_id = paths[paths.Length - 1];
111111
}
112112

113-
RouteMatrixResult result = null;
114-
return Response.FromValue(result, response);
113+
return await WaitForCompletionAsync(async, cancellationToken).ConfigureAwait(false);
115114
}
116115

117116
/// <summary>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#nullable disable
5+
6+
using System.Text.Json;
7+
8+
namespace Azure.Maps.Routing.Models
9+
{
10+
public partial class RouteMatrix
11+
{
12+
internal static RouteMatrix DeserializeRouteMatrix(JsonElement element)
13+
{
14+
if (element.ValueKind == JsonValueKind.Null)
15+
{
16+
return null;
17+
}
18+
int? statusCode = default;
19+
RouteMatrixResultResponse response = default;
20+
foreach (var property in element.EnumerateObject())
21+
{
22+
if (property.NameEquals("statusCode"u8))
23+
{
24+
if (property.Value.ValueKind == JsonValueKind.Null)
25+
{
26+
continue;
27+
}
28+
statusCode = property.Value.GetInt32();
29+
continue;
30+
}
31+
if (property.NameEquals("response"u8))
32+
{
33+
if (property.Value.ValueKind == JsonValueKind.Null)
34+
{
35+
continue;
36+
}
37+
if (statusCode == 200) {
38+
response = RouteMatrixResultResponse.DeserializeRouteMatrixResultResponse(property.Value);
39+
} else {
40+
response = new RouteMatrixResultResponse(null);
41+
}
42+
continue;
43+
}
44+
}
45+
return new RouteMatrix(statusCode, response);
46+
}
47+
48+
/// <summary> Deserializes the model from a raw response. </summary>
49+
/// <param name="response"> The response to deserialize the model from. </param>
50+
internal static RouteMatrix FromResponse(Response response)
51+
{
52+
using var document = JsonDocument.Parse(response.Content);
53+
return DeserializeRouteMatrix(document.RootElement);
54+
}
55+
}
56+
}

sdk/maps/Azure.Maps.Routing/tests/RouteMatrixTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -27,15 +28,19 @@ public async Task CanSyncRequestRouteMatrix()
2728
new GeoPosition(123.751, 45.9375),
2829
new GeoPosition(123.791, 45.96875)
2930
},
30-
Destinations = new List<GeoPosition>() { new GeoPosition(123.767, 45.90625) },
31+
Destinations = new List<GeoPosition>()
32+
{
33+
new GeoPosition(1, 13.5471),
34+
new GeoPosition(123.767, 45.90625),
35+
},
3136
};
3237
var result = await client.GetImmediateRouteMatrixAsync(routeMatrixQuery);
3338

3439
Assert.AreEqual("0.0.1", result.Value.FormatVersion);
3540
Assert.AreEqual(2, result.Value.Matrix.Count);
36-
Assert.AreEqual(1, result.Value.Matrix[0].Count);
41+
Assert.AreEqual(2, result.Value.Matrix[0].Count);
3742
Assert.AreEqual(2, result.Value.Summary.SuccessfulRoutes);
38-
Assert.AreEqual(2, result.Value.Summary.TotalRoutes);
43+
Assert.AreEqual(4, result.Value.Summary.TotalRoutes);
3944
}
4045

4146
[RecordedTest]

0 commit comments

Comments
 (0)