Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

Replaces JsonSerializer.Deserialize<JsonElement>(string) with JsonElement.Parse(string), the dedicated API introduced in System.Text.Json 10.0.0 for parsing JSON strings into JsonElement.

Changes

  • Test servers: Updated InputSchema initialization in TestServer and TestSseServer
  • Unit tests: Updated ElicitationTests and ElicitationTypedTests to use JsonElement.Parse
  • Documentation: Updated elicitation client sample

Example

- InputSchema = JsonSerializer.Deserialize<JsonElement>("""
+ InputSchema = JsonElement.Parse("""
      {
          "type": "object",
          "properties": { ... }
      }
-     """, McpJsonUtilities.DefaultOptions)
+     """)

Note: JsonElement.Parse doesn't accept JsonSerializerOptions as it only parses the structure, not values.

Original prompt

Find all use of JsonSerializer.Deserialize where it's deserializing from a string into a JsonElement and change it to use JsonElement.Parse, which is new to the 10.0.0 version of System.Text.Json we're now using.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…deserialization

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@stephentoub stephentoub marked this pull request as ready for review November 21, 2025 02:53
Copilot AI changed the title [WIP] Update JsonSerializer.Deserialize to JsonElement.Parse Use JsonElement.Parse for string-to-JsonElement deserialization Nov 21, 2025
Copilot AI requested a review from stephentoub November 21, 2025 02:57
Copilot finished work on behalf of stephentoub November 21, 2025 02:57
@stephentoub stephentoub enabled auto-merge (squash) November 21, 2025 02:58
@stephentoub stephentoub merged commit a559bfb into main Nov 21, 2025
10 checks passed
@stephentoub stephentoub deleted the copilot/update-json-deserialization-method branch November 21, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants