Skip to content

fix(hydra): format datetime fields as iso 8601 in cursor pagination urls#8241

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/cursor-pagination-datetime-8085
Jun 4, 2026
Merged

fix(hydra): format datetime fields as iso 8601 in cursor pagination urls#8241
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/cursor-pagination-datetime-8085

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 4, 2026

Summary

Casting a DateTimeInterface to string raises Object of class DateTime could not be converted to string in Hydra\Serializer\PartialCollectionViewNormalizer::cursorPaginationFields(). Format datetime values as ISO 8601 (ATOM) so they serialize cleanly and roundtrip through Doctrine's DateFilter when the client follows the cursor URL.

Reproduction

GetCollection(paginationViaCursor: [['field' => 'createdAt', 'direction' => 'DESC']], paginationPartial: true) on an entity whose createdAt is a DateTimeImmutable (e.g. Gedmo Timestampable) returned HTTP 500 on the listing endpoint.

Test plan

  • Added functional test tests/Functional/JsonLd/CursorPaginationDateTimeTest.php (red without fix, green with).
  • DatedCursorDummy fixture under tests/Fixtures/TestBundle/Entity/Issue8085/.
  • vendor/bin/phpunit src/Hydra/Tests tests/Functional/JsonLd/CursorPaginationDateTimeTest.php — 56 tests, 227 assertions, OK.
  • PHPStan + php-cs-fixer clean on changed files.

Fixes #8085

Casting a DateTimeInterface to string raises "Object of class DateTime
could not be converted to string". Format datetimes as ISO 8601 (ATOM)
so the cursor URL roundtrips through Doctrine's date filter.

Fixes api-platform#8085
@soyuka soyuka merged commit ca8fbf9 into api-platform:4.3 Jun 4, 2026
107 of 108 checks passed
@soyuka soyuka deleted the fix/cursor-pagination-datetime-8085 branch June 4, 2026 13:56
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.

1 participant