[JsonStreamer] Max depth handling and JSON errors #59646
Merged
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.
Until now, max depth was handled like the following:
DataModelNodeInterface
that is at most 512 deep, and adding aExceptionNode
when this depth is reached.ExceptionNode
.But this approach creates some issues:
DataModelNodeInterface
contains useless repeated nodes and is memory-consuming in case of self-referencing objects.This PR fixes these issues by using another approach:
DataModelNodeInterface
(like what is done for decoding). These ghosts will prevent nodes to be repeated.00:03.877
to00:00.122
).json_encode
depending on the current depth:Moreover, JSON encoding errors were not gathered at all.
That's why this PR updates the
json_encode
call to use theJSON_THROW_ON_ERROR
flag, and catches/convert the resulting exceptions toNotEncodableValueException
:And the
MaxDepthException
has been converted to aNotEncodableValueException
with the"Maximum stack depth exceeded"
message to be the same as the nativejson_encode
max depth exception.