Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified, and the change includes focused regression coverage and corresponding diagnostic/API updates for the JSON materialization scenarios.
No open issues 🎉
2 files not reviewed
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs: Generated filesrc/EFCore/Properties/CoreStrings.Designer.cs: Generated file
What changed in this PR
This pull request improves diagnostics for malformed JSON during relational materialization and primitive JSON collection deserialization. Generic token-type errors are replaced with messages describing the expected JSON shape and relevant structural or element type.
Changes:
- Adds contextual errors for JSON object/array mismatches and invalid or null collection elements.
- Passes structural-property metadata through JSON collection include processing and corrects stale token reporting.
- Adds reader/writer and relational regression tests, diagnostic resources, generated accessors, and API baseline updates.
- Review note: add focused coverage for nullable value-type JSON structural projections with an array root.
| File | Description |
|---|---|
test/EFCore.Tests/Storage/Json/JsonCollectionReaderWriterTest.cs |
Tests descriptive errors from primitive collection JSON reader/writers. |
test/EFCore.Relational.Specification.Tests/Query/JsonQueryRelationalTestBase.cs |
Updates expected diagnostics and adds include-path regression tests. |
src/EFCore/Storage/Json/JsonCollectionOfStructsReaderWriter.cs |
Reports collection element type and expected JSON token context. |
src/EFCore/Storage/Json/JsonCollectionOfReferencesReaderWriter.cs |
Reports collection element type and expected JSON token context. |
src/EFCore/Storage/Json/JsonCollectionOfNullableStructsReaderWriter.cs |
Reports collection element type and expected JSON token context. |
src/EFCore/Properties/CoreStrings.resx |
Adds primitive collection diagnostic resources. |
src/EFCore/Properties/CoreStrings.Designer.cs |
Generates accessors for the new core diagnostic resources. |
src/EFCore/EFCore.baseline.json |
Records the new CoreStrings API surface. |
src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs |
Supplies structural metadata to included JSON collection materialization. |
src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.ClientMethods.cs |
Adds descriptive root and element diagnostics and corrects token reporting. |
src/EFCore.Relational/Properties/RelationalStrings.resx |
Adds relational JSON shape and collection diagnostic resources. |
src/EFCore.Relational/Properties/RelationalStrings.Designer.cs |
Generates accessors for the new relational diagnostic resources. |
src/EFCore.Relational/EFCore.Relational.baseline.json |
Records the new RelationalStrings API surface. |
Review effort: Lite
…aterialization - Pass the structural property to IncludeJsonEntityCollection so top-level JSON collections throw JsonEntityCollectionNullElement/JsonEntityCollectionExpectedObject for invalid elements - Name the structural type or property and the expected JSON object/array when the root JSON token doesn't match - Report the current token instead of the stale StartObject token in the EndObject checks - Include the element type in the exceptions thrown by the primitive collection JsonValueReaderWriters Fixes dotnet#39486
Sean-mn
force-pushed
the
fix/json-invalid-token-type-exceptions
branch
from
November 7, 2026 17:52
6660f6f to
58fc5c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #39486
Description
Follow-up to #39485: replaces the remaining generic
Invalid token type: '{tokenType}'.exceptions thrown during JSON materialization with messages that name what was being materialized and what JSON was expected.IncludeJsonEntityCollection(as a liftable constant, likeMaterializeJsonEntityCollection), sonull/ non-object elements in top-level JSON collections throwRelationalStrings.JsonEntityCollectionNullElement/RelationalStrings.JsonEntityCollectionExpectedObject.RelationalStrings.JsonStructuralTypeExpectedObject(MaterializeJsonStructuralType,MaterializeJsonNullableValueStructuralType,IncludeJsonEntityReference) andRelationalStrings.JsonEntityCollectionExpectedArray(MaterializeJsonEntityCollection,IncludeJsonEntityCollection).EndObjectchecks in both collection methods now reportmanager.CurrentReader.TokenTypeinstead of the staleStartObjecttoken.JsonCollectionOfStructsReaderWriter,JsonCollectionOfNullableStructsReaderWriterandJsonCollectionOfReferencesReaderWriternow throwCoreStrings.JsonCollectionExpectedArray/CoreStrings.JsonCollectionInvalidElement, which include the element type.Try_project_collection_but_JSON_is_entity/Try_project_reference_but_JSON_is_collectionassertions, added include-path tests inJsonQueryRelationalTestBase, and addedJsonCollectionReaderWriterTest. TheEndObjectfix isn't covered by a test since that branch isn't reachable with valid shapers.