Skip to content

Commit 2b9b801

Browse files
committed
[JsonStreamer] Fix decoding iterable lists
1 parent 9d93fb4 commit 2b9b801

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Symfony/Component/JsonStreamer/Read/PhpAstBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,12 @@ private function buildCollectionNodeStatements(CollectionNode $node, bool $decod
379379
? $this->builder->funcCall($this->builder->var('iterable'), [$this->builder->var('stream'), $this->builder->var('data')])
380380
: $this->builder->funcCall($this->builder->var('iterable'), [$this->builder->var('data')]);
381381

382+
$collectionKeyType = $node->getType()->getCollectionKeyType();
383+
382384
$prepareDataStmts = $decodeFromStream ? [
383385
new Expression(new Assign($this->builder->var('data'), $this->builder->staticCall(
384386
new FullyQualified(Splitter::class),
385-
$node->getType()->isList() ? 'splitList' : 'splitDict',
387+
($collectionKeyType instanceof BuiltinType && TypeIdentifier::INT === $collectionKeyType->getTypeIdentifier()) ? 'splitList' : 'splitDict',
386388
[$this->builder->var('stream'), $this->builder->var('offset'), $this->builder->var('length')],
387389
))),
388390
] : [];

src/Symfony/Component/JsonStreamer/Tests/JsonStreamReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testReadCollection()
8787
$this->assertRead($reader, function (mixed $read) {
8888
$this->assertIsIterable($read);
8989
$this->assertSame([true, false], iterator_to_array($read));
90-
}, '{"0": true, "1": false}', Type::iterable(Type::bool(), Type::int()));
90+
}, '[true, false]', Type::iterable(Type::bool(), Type::int()));
9191
}
9292

9393
public function testReadObject()

0 commit comments

Comments
 (0)