serializer
serializer copied to clipboard
Exclude Strategy with Until not working exepcted with `.x`
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Steps required to reproduce the problem
We are using the versioning of the jms serializer.
I first did have this:
<property name="sections" expose="true" since-version="3.0"/>
<virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="2.0" />
<virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="3.0" />
Then I did find out that the areas
is still returned when using 3.0
version. So I did see in the docs: https://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies
There is something like 1.0.x
used so I did use:
<property name="sections" expose="true" since-version="3.0"/>
<virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="1.x" />
<virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="2.x" />
but this didn't work the areas
where not returned when requested with 2.0
Expected Result
**3.0**: Return `sections` without `areas`:
"sections": [
{
"_hash": "@string@",
"uuid": "@string@",
"name": "Section 1",
"areas": [
{
"_hash": "@string@",
"uuid": "@string@",
"name": "1"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "1A"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "2A"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "2B"
}
]
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "Section 2",
"areas": [
{
"_hash": "@string@",
"uuid": "@string@",
"name": "1"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "1A"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "2A"
},
{
"_hash": "@string@",
"uuid": "@string@",
"name": "2B"
}
]
}
],
**2.0** Return `areas` without `sections`:
"areas": [
{
"section": "Section 1",
"areas": [
"1",
"1A",
"2A",
"2B"
]
},
{
"section": "Section 2",
"areas": [
"1",
"1A",
"2A",
"2B"
]
}
],
**1.0** Return `areas` in old format without `sections`:
"areas": [
"1",
"1A",
"2A",
"2B",
"1",
"1A",
"2A",
"2B"
],
Actual Result
See above.
Current workaround
Currently I did workaround by using .9999 as until version:
<property name="sections" expose="true" since-version="3.0"/>
<virtual-property name="areas_without_section" serialized-name="areas" method="getAreasWithoutSections" expose="true" since-version="1.0" until-version="1.9999" />
<virtual-property name="areas" serialized-name="areas" method="getAreas" expose="true" since-version="2.0" until-version="2.9999" />
The version exclusion strategy uses under the hood https://www.php.net/manual/en/function.version-compare.php
Whatever is supported by version_compare
should work here.
It would be nice to move to https://github.com/composer/semver instead of version_compare
I don't think that the 1.0.x
example from the docs have ever worked.
It would be nice to move to https://github.com/composer/semver instead of version_compare
I gave this a try in https://github.com/schmittjoh/serializer/pull/1361 by adding a version-constraints
attribute/VersionConstraints
annotation which accept composer version constraints