-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Description
Sometimes we need to have a version control on the properties which are serialized.
Currently the Symfony Serializer don't provide a simple and scalable way to do it.
Example
As JmsSerializer do, it would be great to provide two annotations @Since
and @Until
who require the version as value (cf. example below):
class User
{
/**
* @Since("1.1.0")
*/
private $email;
/**
* @Until("1.0.x")
*/
private $username;
}
Of course xml and yaml mappings need to support it too.
The version to compare to might be passed via the serializer context
$serializer->serialize($myObject, 'json', ['version' => '1.1.0']);
The version numbers must be in the standardized PHP version format to make it compatible with the version_compare
function (https://www.php.net/manual/en/function.version-compare.php)
Example of results:
Version | Since | Until | Serialized |
---|---|---|---|
1.0.0 | 0.9 | ~ | ✓ |
1.9 | 2.0 | ~ | ✗ |
2.3 | 1.3 | 2.1 | ✗ |
2.3 | ~ | 2.1 | ✗ |
2.4 | 1.1 | 3.x | ✓ |
If this feature make sense, I can make a PR 🙂.