Skip to content

[Json] Remove unnecessary Debug.Asserts #116833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public override void Write(Utf8JsonWriter writer, JsonArray? value, JsonSerializ
case JsonTokenType.Null:
return null;
default:
Debug.Assert(false);
throw ThrowHelper.GetInvalidOperationException_ExpectedArray(reader.TokenType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public override void Write(Utf8JsonWriter writer, JsonObject? value, JsonSeriali
case JsonTokenType.Null:
return null;
default:
Debug.Assert(false);
throw ThrowHelper.GetInvalidOperationException_ExpectedObject(reader.TokenType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,5 +889,13 @@ public static void RemoveRange_FreshlyDeserialized()

static JsonArray PrepareData() => JsonSerializer.Deserialize<JsonArray>("[1,2,3,4,5]");
}

[Theory]
[InlineData("42")]
[InlineData("{}")]
public static void Deserialize_WrongType(string json)
{
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<JsonArray>(json));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1718,5 +1718,13 @@ public static void JsonObject_NestedDuplicatePropertyCaseInsensitiveThrows()
() => JsonSerializer.Deserialize<JsonNode>(jsonPayload, options),
"An item with the same key has already been added.");
}

[Theory]
[InlineData("42")]
[InlineData("[]")]
public static void Deserialize_WrongType(string json)
{
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<JsonObject>(json));
}
}
}
Loading