serializer icon indicating copy to clipboard operation
serializer copied to clipboard

Added default_skip_when_empty option as config using the exclusionStrategy

Open vasilake-v opened this issue 4 years ago • 4 comments

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

vasilake-v avatar Oct 25 '20 21:10 vasilake-v

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 avatar Nov 08 '20 09:11 goetas

@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 ?

vasilake-v avatar Nov 23 '20 18:11 vasilake-v

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!

vasilake-v avatar Oct 29 '21 06:10 vasilake-v

Hi @goetas i've rebased the pull-request branch.

I'll check if i can improve/lower the complexity reported for
SerializationGraphNavigator

vasilake-v avatar May 24 '22 07:05 vasilake-v