Skip to content

Conversation

@senaria
Copy link

@senaria senaria commented Nov 28, 2025

Q A
Branch? 4.2
Tickets Closes #7563
License MIT
Doc PR N/A (bug fix, no doc changes)

Description
Fix ObjectMapperProvider to correctly handle unpaginated collections (arrays) when using stateOptions with the Map attribute.

Problem
When using GetCollection with pagination=false (or paginationEnabled: false), the ObjectMapperProvider was skipping the object mapping because it only checked for is_object($data). Arrays returned by unpaginated collection endpoints were not being mapped, causing serialization errors like:

Can't get a way to read the property "X" in class "Entity"

Solution
The fix separates the early-return conditions:

First check if mapping should be skipped entirely (no objectMapper or operation cannot map)
Then check if the data type is mappable (object or array)
For arrays, the provider now maps each element using array_map(), similar to how paginated collections are handled.

Changes
Modified ObjectMapperProvider::provide() to handle array data
Added unit tests for ObjectMapperProvider covering all scenarios (single object, paginated, unpaginated, empty cases)
Added functional test (Issue7563Test) demonstrating the fix with a real API endpoint

@senaria senaria force-pushed the fix/object-mapper-provider-unpaginated-collection-handling branch 2 times, most recently from 881cfe8 to a68594c Compare November 28, 2025 14:03
@senaria
Copy link
Author

senaria commented Nov 28, 2025

Not sure why half of the stuff fails, but seem to be unrelated to my changes, looking at it. I ran cs-fixer on my files and obviously check the tests locally.

If this blocks it getting merged I would love to get some infos how I get all of these checks green.

@senaria
Copy link
Author

senaria commented Nov 28, 2025

@soyuka this PR might interest you since I saw you doing stuff on the ObjectMapperProcessor.

@soyuka soyuka changed the base branch from main to 4.2 November 30, 2025 12:59
@soyuka soyuka force-pushed the fix/object-mapper-provider-unpaginated-collection-handling branch 2 times, most recently from 4aeac7f to b359494 Compare November 30, 2025 17:14
@soyuka soyuka force-pushed the fix/object-mapper-provider-unpaginated-collection-handling branch from b359494 to 0e86a6a Compare November 30, 2025 19:34
@soyuka soyuka changed the title fix(object-mapper) ObjectMapperProvider can handle non paginated coll… fix(state): object mapper with list<object> Nov 30, 2025
@soyuka soyuka merged commit 99c45de into api-platform:4.2 Nov 30, 2025
128 checks passed
@soyuka
Copy link
Member

soyuka commented Nov 30, 2025

Thanks!

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.

ObjectMapperProvider does not handle $data for requests with pagination=false

2 participants