Skip to content

JsonStream should not always be seekableΒ #10

@georgebarbarosie

Description

@georgebarbarosie

If a BufferJsonEncoder encodes a Generator, or a value that points to a Generator, JsonStream is no longer seekable. This breaks passing JsonStream as the response body of some frameworks. Slim v4 in particular attempts to read the first byte of a seekable body to determine if the response is empty, then rewinds.

The exception triggered is Cannot rewind a generator that was already run, caused by calling AbstractJsonEncoder::getIterator() twice on the same generator (JsonBuffer::rewind() calls AbstractJsonEncoder::rewind() which resets the stack).

I am pretty sure it's impossible to make JsonStream detect if it's safe to return isSeekable()==true, but I think it would be useful to have a setSeekable(bool $value) method to mark a stream as unseekable for such cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions