versioning_objects.rst 850 B

12345678910111213141516171819202122232425262728293031323334353637
  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. .. code-block :: php
  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. .. code-block :: php
  25. <?php
  26. $serializer->setVersion('1.0');
  27. $serializer->serialize(new VersionObject(), 'json');