Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Versionable serialization #24

Merged
merged 36 commits into from
Jun 20, 2019

Conversation

e1himself
Copy link
Collaborator

@e1himself e1himself commented Jun 13, 2019

The idea is to have different serializers (and unserializers) that can handle JSONs of different versions.

$prev_version_json = $serializer->serialize($value, '0.44');
$current_version_json = $serializer->serialize($value);

Changelog

  • Model classes are not JsonSerializable anymore (BC break)

  • Add (optional) version property to all serialized Value objects (BC break)

  • Unserializer class has been dropped in favour of Serializer (BC break)
    Also the namespace has changed:
    Prezly\Slate\UnserializerPrezly\Slate\Serialization\Serializer.

  • Serializer class changed interface (BC break)

    class Serializer implements ValueSerializer 
    {
        /**
         * Serialize value to JSON
         *
         * Optionally you can provide desired serialization version.
         *
         * If no version argument provided, default serialization version
         * will be used (which is set to LATEST by default).
         *
         * @param \Prezly\Slate\Model\Value $value
         * @param string|null $version
         * @return string
         */
        public function toJson(Value $value, ?string $version = null): string
    
        /**
         * Unserialize value from JSON
         *
         * Optional you can provide serialization version to use
         * in case if value JSON does not have "version" property.
         *
         * If no version argument is given, default serialization
         * version will be implied (which is set to LATEST by default).
         *
         * @param string $value
         * @param string|null $default_version
         * @return \Prezly\Slate\Model\Value
         */
        public function fromJson(string $value, ?string $default_version = null): Value;
    }
    • Implement VersionSerializer for v0.40 ... v0.45
    • Implement VersionSerializer for v0.46+

@e1himself e1himself added enhancement New feature or request refactoring labels Jun 13, 2019
@e1himself e1himself self-assigned this Jun 13, 2019
@e1himself e1himself marked this pull request as ready for review June 20, 2019 09:29
@e1himself e1himself merged commit cce06f5 into master Jun 20, 2019
@e1himself e1himself deleted the feature/versionable-serialization branch June 20, 2019 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant