Commit 6e42b36
committed
bug symfony#61561 [JsonStreamer] Fix decoding iterable lists (mtarld)
This PR was merged into the 7.3 branch.
Discussion
----------
[JsonStreamer] Fix decoding iterable lists
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix symfony#61559
| License | MIT
Because a `list<T>` is a subtype of `array<T>`, an `iterable<T>` cannot be a list.
This means that, as said [here](symfony#59308 (comment)):
> There is no way to be sure that keys of an iterable are successive (even if they are integers).
> And if keys are not successive, the resulting JSON structure is an object and not an array.
> According, to the [JSON specification](https://datatracker.ietf.org/doc/html/rfc8259#section-4), object' keys must be strings, and not integers.
This imply that it is right now impossible to "yield" items from `[{"itemId": 1, "modificationDate": "2025-10-10"}]` - it can only be yielded from `{"0": {"itemId": 1, "modificationDate": "2025-10-10"}}`.
I think that in the real world, a lot of people want to be able to yield items from `[...]`, even though it does not stick with the JSON specification.
This PR is doing the trade-off of considering `iterable<int, Anything>` as an "iterable list" (like `list<Anything>` but not cast to array).
Commits
-------
2b9b801 [JsonStreamer] Fix decoding iterable listsFile tree
2 files changed
+4
-2
lines changed- src/Symfony/Component/JsonStreamer
- Read
- Tests
2 files changed
+4
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
382 | 384 | | |
383 | 385 | | |
384 | 386 | | |
385 | | - | |
| 387 | + | |
386 | 388 | | |
387 | 389 | | |
388 | 390 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
0 commit comments