Core supports JSON and XML, as well as HAL-JSON. It is easy to add support for other formats.
Adding basic support
As explained in How the Serializer works, the serialization process has two parts, normalization and encoding.
If the array structure created by core's default Normalizers is acceptable for your format, then you can simply add an Encoder. For example, this is how support for YAML is added to core.
- Create an encoder
Your Encoder should implement EncoderInterface.
- Register the encoder with the container
Any service added to the container which is tagged with 'encoder' will be added to the encoder array which is passed into the Serializer. This code is placed in your module's Bundle class in the
Additionally, if you want this format to be configurable via REST module, you should add a format attribute to the encoder tag. The array should be keyed by the format short name and the value should be the human readable name, which will be used in the REST UI.
->addTag('encoder', array('format' => array('yaml' => 'YAML')));
- If the MIME type of your format isn't registered, register it
The default MIME types are defined in
Request::initializeFormats(). If the MIME type of your format is not listed there, you need to add it to the Request object using
This can be done with an event subscriber which is listening for onRequestEvent.
// Insert example once YAML patch is finalized, http://drupal.org/node/1897612