serializer icon indicating copy to clipboard operation
serializer copied to clipboard

Exclude properties based on semver constraints

Open W0rma opened this issue 3 years ago • 2 comments

Q A
Bug fix? no
New feature? yes
Doc updated yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1312
License MIT

This PR adds the possibility to exclude properties from serialization based on version constraints accepted by composer.

Example:

use JMS\Serializer\Annotation\VersionConstraints;

class Author
{
    #[VersionConstraints('^6.1')]
    public function getAge(): int
    {
        return 61;
    }
}

I'm not sure if VersionConstraints is a good name or if there are better alternatives. Suggestions are welcome :)

W0rma avatar Oct 31 '21 12:10 W0rma

Do you think that we should keep Until and Since attributes or they should be deprecated?

@scyzoryck Good point. I think they should be deprecated since version constraints provide even more flexibility. Do you agree?

W0rma avatar Nov 05 '21 08:11 W0rma

Thanks. Looks good to me.

I think they should be deprecated since version constraints provide even more flexibility. Do you agree?

It was my initial thought - as basically new constraint covers all functionalities provided by older constraints. On the other hand new one requires external dependency, so keeping simpler constraints might made sense too. @goetas - what do you think about it?

scyzoryck avatar Nov 05 '21 13:11 scyzoryck