Skip to content

Commit d3a0df0

Browse files
feature #60730 [JsonStreamer] Add include_null_properties option (mtarld)
This PR was merged into the 7.4 branch. Discussion ---------- [JsonStreamer] Add `include_null_properties` option | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT A really common use case in APIs is to be able to skip properties with `null` value (for instance, this use case is required to make the JsonStreamer component working with API Platform). ~This PR adds the option `skip_null_properties` that allow to skip `null` properties during stream writing.~ ~This PR skips properties with `nulln` values during stream writing.~ This PR adds the option `include_null_properties` that allow to encode `null` properties during stream writing. This requires to define dynamic object prefixes (such as `''` and `','`). That's why the PHP generated code has been updated to merge as many prefixes as possible in raw strings and therefore yield a bit bigger chunks. Commits ------- d662f85 [JsonStreamer] Add `include_null_properties` option
2 parents 8c3d388 + d662f85 commit d3a0df0

23 files changed

+291
-148
lines changed

src/Symfony/Component/JsonStreamer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Remove `nikic/php-parser` dependency
88
* Add `_current_object` to the context passed to value transformers during write operations
9+
* Add `include_null_properties` option to encode the properties with `null` value
910

1011
7.3
1112
---

src/Symfony/Component/JsonStreamer/JsonStreamWriter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
/**
3030
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
3131
*
32-
* @implements StreamWriterInterface<array<string, mixed>>
32+
* @implements StreamWriterInterface<array{
33+
* include_null_properties?: bool,
34+
* ...<string, mixed>,
35+
* }>
3336
*
3437
* @experimental
3538
*/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Symfony\Component\JsonStreamer\Tests\Fixtures\Model;
4+
5+
use Symfony\Component\JsonStreamer\Attribute\StreamedName;
6+
7+
class DummyWithDollarNamedProperties
8+
{
9+
#[StreamedName('$foo')]
10+
public bool $foo = true;
11+
12+
#[StreamedName('{$foo->bar}')]
13+
public bool $bar = true;
14+
}

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/double_nested_list.php

Lines changed: 25 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nested_list.php

Lines changed: 17 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/null.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nullable_backed_enum.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nullable_object.php

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nullable_object_dict.php

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/JsonStreamer/Tests/Fixtures/stream_writer/nullable_object_list.php

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)