Skip to content
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

Fix to #34960 - System.Text.Json.JsonReaderException: '0x00' is invalid after a single JSON value. Expected end of data #34969

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Oct 24, 2024

When entity or collection of entities is mapped to JSON null value for that object can be represented either as relational null, or as JSON with null value inside 'null'. Problem was that IncludeJsonEntityReference and IncludeJsonEntityCollection were only checking for null value, and not for the JSON 'null'. (MaterializeJsonEntity and MaterializeJsonEntityCollection had the logic for both)

Fix is to add the missing logic so that upon encountering Null token we just return, rather than run shaper code for the entity. Also added some validation that throws if StartObject is not the first token (again, copying logic from MaterializeJsonEntity method)

Fixes #34960

…id after a single JSON value. Expected end of data

When entity or collection of entities is mapped to JSON null value for that object can be represented either as relational null, or as JSON with null value inside 'null'.
Problem was that IncludeJsonEntityReference and IncludeJsonEntityCollection were only checking for null value, and not for the JSON 'null'. (MaterializeJsonEntity and MaterializeJsonEntityCollection had the logic for both)

Fix is to add the missing logic so that upon encountering Null token we just return, rather than run shaper code for the entity. Also added some validation that throws if StartObject is not the first token (again, copying logic from MaterializeJsonEntity method)

Fixes #34960
@maumar maumar requested a review from a team as a code owner October 24, 2024 12:02
@maumar maumar requested a review from roji October 24, 2024 12:03
var manager = new Utf8JsonReaderManager(jsonReaderData, queryContext.QueryLogger);
var tokenType = manager.CurrentReader.TokenType;

if (tokenType == JsonTokenType.Null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider having a switch statement (multiple conditions checking the same tokenType).

{
await base.Seed34960(ctx);

// JSON nulls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check that we throw the correct exceptions for invalid JSON (e.g. scalar, array)?

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.

System.Text.Json.JsonReaderException: '0x00' is invalid after a single JSON value. Expected end of data.
2 participants