Skip to content

Latest commit

 

History

History
101 lines (80 loc) · 2.57 KB

File metadata and controls

101 lines (80 loc) · 2.57 KB

Visitors

When you (de)-serialize your data, the serializer will choose a visitor according to your format (csv, json, ...) and your direction (serialization or deserialization). Each format/direction have a dedicated visitor in order to handle this specific use case.

Built-in

The bundle integrates all the Serializer visitors.

Configuration

Each visitor can be globally configured in your configuration file.

CSV

The CSV visitor can be configured in order to customize how the data should be (de)-serialized when using the CSV format:

ivory_serializer:
    visitors:
        csv:
            delimiter: ","
            enclosure: '"'
            escape_char: "\\"
            key_separator: "."

JSON

The JSON visitor can be configured in order to customize how the data should be (de)-serialized when using the JSON format:

ivory_serializer:
    visitors:
        json:
            max_depth: 512
            options: 0

XML

The XML visitor can be configured in order to customize how the data should be (de)-serialized when using the XML format:

ivory_serializer:
    visitors:
        xml:
            version: "1.0"
            encoding: UTF-8
            format_output: "%kernel.debug%"
            root: result
            entry: entry
            entry_attribute: key

YAML

The YAML visitor can be configured in order to customize how the data should be (de)-serialized when using the YAML format:

ivory_serializer:
    visitors:
        yaml:
            inline: 2
            indent: 4
            options: 0

Custom

<?xml version="1.0" encoding="UTF-8" ?>

<container
    xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services
                        http://symfony.com/schema/dic/services/services-1.0.xsd"
>
    <services>
        <service
            id="acme.serializer.visitor.custom.serialization"
            class="Acme\Serializer\Visitor\Custom\CustomSerializationVisitor"
        >
            <tag name="ivory.serializer.visitor" direction="serialization" format="custom" />
        </service>
        
        <service
            id="acme.serializer.visitor.custom.deserialization"
            class="Acme\Serializer\Visitor\Custom\CustomDeserializationVisitor"
        >
            <tag name="ivory.serializer.visitor" direction="deserialization" format="custom" />
        </service>
    </services>
</container>