Customizing Serialization of API
How to add an existing field to a response?
<?xml version="1.0" ?>
<!-- config/serialization/ProductVariant.xml -->
<serializer
xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Component\Core\Model\ProductVariant">
<attribute name="createdAt">
<group>sylius:shop:product_variant:show</group>
</attribute>
</class>
</serializer># config/serialization/ProductVariant.yaml
Sylius\Component\Core\Model\ProductVariant:
attributes:
createdAt:
groups: ['sylius:shop:product_variant:show']How to add a custom field to a response?
How to add a custom field to a response for Specific Contexts Only (e.g., Shop)?
How to remove a field from a response
How to rename a field of a response
Last updated
Was this helpful?
