Skip to content

Commit 65b8e76

Browse files
authored
Merge pull request #3190 from microsoftgraph/3187-new-mgsitelistitem-field-format-issue-intstr-with-2261
Prevents automatic inference of properties with numeric characters defined as strings. e.g ``{"age":"28"}``"
2 parents c05630a + 769170b commit 65b8e76

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tools/Custom/JsonExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static void ProcessBody(JToken token)
156156
{
157157
JToken parsedValue = JToken.Parse(stringValue);
158158
property.Value = parsedValue; // Replace with unescaped JSON object
159-
ProcessBody(parsedValue); // Recursively process
159+
ProcessBody(stringValue); // Recursively process
160160
}
161161
catch (Newtonsoft.Json.JsonException)
162162
{
@@ -183,7 +183,7 @@ private static void ProcessBody(JToken token)
183183
{
184184
JToken parsedValue = JToken.Parse(stringValue);
185185
jsonArray[i] = parsedValue; // Replace with unescaped JSON object
186-
ProcessBody(parsedValue); // Recursively process
186+
ProcessBody(stringValue); // Recursively process
187187
}
188188
catch (Newtonsoft.Json.JsonException)
189189
{

tools/Tests/JsonUtilitiesTest/JsonExtensionsTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,39 @@ public void RemoveDefaultNullProperties_ShouldRemoveDefaultNullValuesInJsonObjec
246246
Assert.False(result["body"]?["users"][0]?.ToObject<JObject>().ContainsKey("email"));
247247
Assert.True(result["body"]?["users"][0]?["metadata"]?.ToObject<JObject>().ContainsKey("phone"));
248248
}
249+
250+
/*
251+
Test for unescaping json object while maintaining original property definition of values
252+
instead of auto inferencing the type of the value
253+
"fields": "{\r\n \"BasicTag\": \"v2.31.0\",\r\n \"BuildID\": \"3599\",\r\n \"MWSCommitID\": \"a5c7998252f2366c8cbbb03ba46e9b\",\r\n \"MWSTag\": \"v2.21.0\",\r\n \"BasicCommitID\": \"9c3d0f36362dd25caa0da2ecab06a1859ce2\",\r\n \"CustomerCommitID\": \"c40241be9fd2f1cd2f2f2fc961c37f720c\"\r\n}"
254+
*/
255+
[Fact]
256+
public void RemoveDefaultNullProperties_ShouldUnescapeJsonString(){
257+
// Arrange
258+
JObject json = JObject.Parse(@"{
259+
""fields"": ""{\r\n \""BasicTag\"": \""v2.31.0\"",\r\n \""BuildID\"": \""3599\"",\r\n \""MWSCommitID\"": \""a5c7998252f2366c8cbbb03ba46e9b\"",\r\n \""MWSTag\"": \""v2.21.0\"",\r\n \""BasicCommitID\"": \""9c3d0f36362dd25caa0da2ecab06a1859ce2\"",\r\n \""CustomerCommitID\"": \""c40241be9fd2f1cd2f2f2fc961c37f720c\""\r\n}""
260+
}");
261+
262+
String expectedJson = @"{
263+
""fields"": {
264+
""BasicTag"": ""v2.31.0"",
265+
""BuildID"": ""3599"",
266+
""MWSCommitID"": ""a5c7998252f2366c8cbbb03ba46e9b"",
267+
""MWSTag"": ""v2.21.0"",
268+
""BasicCommitID"": ""9c3d0f36362dd25caa0da2ecab06a1859ce2"",
269+
""CustomerCommitID"": ""c40241be9fd2f1cd2f2f2fc961c37f720c""
270+
}
271+
}";
272+
273+
// Act
274+
//Convert Json object to string then pass it to RemoveAndReplaceSlashes method
275+
string cleanedJson = json.ToString()?.ReplaceAndRemoveSlashes();
276+
277+
// Assert
278+
Assert.Equal(NormalizeJson(expectedJson), NormalizeJson(cleanedJson));
279+
}
280+
281+
282+
249283
}
250284

0 commit comments

Comments
 (0)