serializer
serializer copied to clipboard
Added default_skip_when_empty option as config using the exclusionStrategy
Extended the context to include the option to enable SkipWhenEmpty as a default behaviour for properties.
The ExclusionStrategy approach was used to enable this.
It is also related to https://github.com/schmittjoh/JMSSerializerBundle/issues/789 And I will prepare a pull request for that repo. also when this will be merged
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
Doc updated | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | https://github.com/schmittjoh/JMSSerializerBundle/issues/789 |
License | MIT |
Hi, thanks for the PR. I like the idea, but I'm not sure that works as expected. IMO it will skip all the props when enabled. To check it, can you please also add few props in ObjectWithEmptyArrayAndHashNotAnnotated
that are not empty, and check that those do not get skipped?
@goetas , you were right. After adding the test tests/Fixtures/ObjectWithEmptyArrayAndHashNotAnnotated.php i realized where was the mistake. I did some refactorings of the implementation and, basically, extended the Exclusion mechanism with additional interface that describes signature for an exclusion method that would accept a property value also, whenever the case.
i came to this implementation, which seems cleaner in my view. I considering the:
- approach of
expressionExclusionStrategy
private property assigned in constructor -- bad: one more prop. polouting class - extending the original
ExclusionStrategyInterface
with another method -- bad: other classes would have to implement the method
Maybe there are any other ideas that i haven't thought about ?
Hi, thanks for the PR. I like the idea, but I'm not sure that works as expected. IMO it will skip all the props when enabled. To check it, can you please also add few props in
ObjectWithEmptyArrayAndHashNotAnnotated
that are not empty, and check that those do not get skipped?
Hi @goetas Do you think we could go forward with this pull request, or are there any other concerns that i could fix ?
Thanks!
Hi @goetas i've rebased the pull-request branch.
I'll check if i can improve/lower the complexity reported for
SerializationGraphNavigator