Skip to content

Latest commit

 

History

History
307 lines (239 loc) · 11.5 KB

configuration.rst

File metadata and controls

307 lines (239 loc) · 11.5 KB

Configuration

Handlers

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

The possible tag attributes are the following:

  • format: The format that you want to handle; defaults to all formats.
  • type: The type name that you want to handle; defaults to all types.
  • direction: The direction (serialization, or deserialization); defaults to both.
  • method: The method to invoke on the my_handler service.

- instance: The specific serializer instance name; defaults to all types when not specified., default if you want to apply it only to the main instance.

- instance: The specific serializer instance name; defaults to all types when not specified., default if you want to apply it only to the main instance.

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 Symfony 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.

- instance: The specific serializer instance name; defaults to all types., default if you want to apply it only to the main instance.

Expression Language

You can add custom expression functions using the jms.expression.function_provider tag.

A functions provider for the Symfony Expression Language might look something as this:

You can read more about it on the official expression function providers documentation.

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.project_dir%/serializer/app, then your metadata file must be named: %kernel.project_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: