Use JsonElement.Parse for string-to-JsonElement deserialization (#1002)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2025-11-21 11:00:11 +02:00 • committed by GitHub
commit a559bfb891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 48 deletions

View file

@ -43,13 +43,13 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
{
Name = "FirstCustomTool",
Description = "First tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};
@ -61,13 +61,13 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
{
Name = "SecondCustomTool",
Description = "Second tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};
@ -79,13 +79,13 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
{
Name = "FinalCustomTool",
Description = "Third tool returned by custom handler",
InputSchema = JsonSerializer.Deserialize<JsonElement>("""
InputSchema = JsonElement.Parse("""
{
"type": "object",
"properties": {},
"required": []
}
""", McpJsonUtilities.DefaultOptions),
"""),
}],
};

View file

@ -120,18 +120,18 @@ public partial class ElicitationTests : ClientServerTestBase
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
["prop1"] = (JsonElement)JsonSerializer.Deserialize("""
["prop1"] = JsonElement.Parse("""
"string result"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
["prop2"] = (JsonElement)JsonSerializer.Deserialize("""
"""),
["prop2"] = JsonElement.Parse("""
42
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
["prop3"] = (JsonElement)JsonSerializer.Deserialize("""
"""),
["prop3"] = JsonElement.Parse("""
true
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
["prop4"] = (JsonElement)JsonSerializer.Deserialize("""
"""),
["prop4"] = JsonElement.Parse("""
"option2"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
"""),
},
};
}

View file

@ -177,24 +177,24 @@ public partial class ElicitationTypedTests : ClientServerTestBase
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
[nameof(SampleForm.Name)] = (JsonElement)JsonSerializer.Deserialize("""
[nameof(SampleForm.Name)] = JsonElement.Parse("""
"Alice"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
[nameof(SampleForm.Age)] = (JsonElement)JsonSerializer.Deserialize("""
"""),
[nameof(SampleForm.Age)] = JsonElement.Parse("""
30
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
[nameof(SampleForm.Active)] = (JsonElement)JsonSerializer.Deserialize("""
"""),
[nameof(SampleForm.Active)] = JsonElement.Parse("""
true
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
[nameof(SampleForm.Role)] = (JsonElement)JsonSerializer.Deserialize("""
"""),
[nameof(SampleForm.Role)] = JsonElement.Parse("""
"Admin"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
[nameof(SampleForm.Score)] = (JsonElement)JsonSerializer.Deserialize("""
"""),
[nameof(SampleForm.Score)] = JsonElement.Parse("""
99.5
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
[nameof(SampleForm.Created)] = (JsonElement)JsonSerializer.Deserialize("""
"""),
[nameof(SampleForm.Created)] = JsonElement.Parse("""
"2023-08-27T03:05:00"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
"""),
},
};
},
@ -228,15 +228,15 @@ public partial class ElicitationTypedTests : ClientServerTestBase
Action = "accept",
Content = new Dictionary<string, JsonElement>
{
["firstName"] = (JsonElement)JsonSerializer.Deserialize("""
["firstName"] = JsonElement.Parse("""
"Bob"
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
["zipCode"] = (JsonElement)JsonSerializer.Deserialize("""
"""),
["zipCode"] = JsonElement.Parse("""
90210
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
["isAdmin"] = (JsonElement)JsonSerializer.Deserialize("""
"""),
["isAdmin"] = JsonElement.Parse("""
false
""", McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonElement)))!,
"""),
},
};
},