Skip to content

Latest commit

 

History

History
240 lines (191 loc) · 8.91 KB

configuration.rst

File metadata and controls

240 lines (191 loc) · 8.91 KB

Configuration

Handlers

You can register any service as a handler by adding either the jms_serializer.handler, or the jms_serializer.subscribing_handler.

Event Dispatcher

You can use the tags jms_serializer.event_listener, or jms_serializer.event_subscriber in order to register a listener.

The semantics are mainly the same as registering a regular Symfony2 event listener except that you can specify some additional attributes:

  • format: The format that you want to listen to; defaults to all formats.
  • class: The type name that you want to listen to; defaults to all types.
  • direction: The direction (serialization, or deserialization); defaults to both.

Defining Metadata

To define the metadata using YAML or XML, you need to specify their location and to which PHP namespace prefix they refer.

Suppose you want to define the metadata using YAML for the classes in the App\\Entity namespace prefix and the configured path is %kernel.root_dir%/serializer/app, then your metadata file should be named: %kernel.root_dir%/serializer/app/Product.yml.

This feature is also useful for Overriding Third-Party Metadata. Sometimes you want to serialize objects which are shipped by a third-party bundle. Such a third-party bundle might not ship with metadata that suits your needs, or possibly none, at all. In such a case, you can override the default location that is searched for metadata with a path that is under your control.

Changing the Object Constructor

A Constructor class is used to construct new objects during deserialization. The default constructor uses the unserialize function to construct objects. Other constructors are configured as services. You can set the constructor by changing the service alias:

Extension Reference

Below you find a reference of all configuration options with their default values: