versioning_objects.rst 807 B

1234567891011121314151617181920212223242526272829303132333435
  1. Versioning Objects
  2. ------------------
  3. JMSSerializerBundle comes by default with a very neat feature which allows
  4. you to add versioning support to your objects, e.g. if you want to
  5. expose them via an API that is consumed by a third-party:
  6. ::
  7. <?php
  8. class VersionedObject
  9. {
  10. /**
  11. * @Until("1.0.x")
  12. */
  13. private $name;
  14. /**
  15. * @Since("1.1")
  16. * @SerializedName("name")
  17. */
  18. private $name2;
  19. }
  20. .. note ::
  21. ``@Until``, and ``@Since`` both accept a standardized PHP version number.
  22. If you have annotated your objects like above, you can serializing different
  23. versions like this::
  24. <?php
  25. $serializer->setVersion('1.0');
  26. $serializer->serialize(new VersionObject(), 'json');