exclusion_strategies.rst 826 B

123456789101112131415161718192021222324252627282930
  1. Defining which properties should be serialized
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. The default exclusion policy is to exclude nothing, that is all properties of the
  4. object will be serialized. If you only want to expose a few of the properties,
  5. then it is easier to change the exclusion policy, and only mark these few properties:
  6. .. code-block :: php
  7. <?php
  8. use JMS\SerializerBundle\Annotation\ExclusionPolicy;
  9. use JMS\SerializerBundle\Annotation\Expose;
  10. /**
  11. * The following annotations tells the serializer to skip all properties which
  12. * have not marked with @Expose.
  13. *
  14. * @ExclusionPolicy("all")
  15. */
  16. class MyObject
  17. {
  18. private $foo;
  19. private $bar;
  20. /**
  21. * @Expose
  22. */
  23. private $name;
  24. }