-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added default_skip_when_empty option as config using the exclusionStr…
…ategy approach Updated documentation
- Loading branch information
slava-v
authored and
slava-v
committed
Oct 25, 2020
1 parent
8d7113e
commit 25ca44d
Showing
8 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Exclusion; | ||
|
||
use JMS\Serializer\Context; | ||
use JMS\Serializer\Metadata\ClassMetadata; | ||
use JMS\Serializer\Metadata\PropertyMetadata; | ||
|
||
class SkipWhenEmptyExclusionStrategy implements ExclusionStrategyInterface | ||
{ | ||
public function shouldSkipClass(ClassMetadata $metadata, Context $context): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function shouldSkipProperty(PropertyMetadata $property, Context $context): bool | ||
{ | ||
return $property->skipWhenEmpty | ||
|| ($context->hasAttribute(Context::ATTR_SKIP_WHEN_EMPTY) | ||
&& $context->getAttribute(Context::ATTR_SKIP_WHEN_EMPTY) | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Fixtures/ObjectWithEmptyArrayAndHashNotAnnotated.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\Serializer\Tests\Fixtures; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
||
class ObjectWithEmptyArrayAndHashNotAnnotated | ||
{ | ||
/** | ||
* @Serializer\Type("array<string,string>") | ||
*/ | ||
private $hash = []; | ||
/** | ||
* @Serializer\Type("array<string>") | ||
*/ | ||
private $array = []; | ||
|
||
private $object = []; | ||
|
||
public function __construct() | ||
{ | ||
$this->object = new InlineChildEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/Serializer/xml/default_skip_when_empty_disabled_object.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<a> | ||
<xxx><![CDATA[yyy]]></xxx> | ||
<inner> | ||
<xxx><![CDATA[yyy]]></xxx> | ||
</inner> | ||
</a> | ||
</result> |
2 changes: 2 additions & 0 deletions
2
tests/Serializer/xml/default_skip_when_empty_enabled_object.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result/> |