You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(serializer): deprecation of annotations and fix broken link (#2118)
- Added detailed documentation about the deprecation of annotations in favor of attributes for Symfony >= 7.0.
- Updated configuration examples for both annotation-based and attribute-based serializers.
- Fixed a broken link to Symfony Flex documentation.
Copy file name to clipboardexpand all lines: core/serialization.md
+53-5
Original file line number
Diff line number
Diff line change
@@ -49,18 +49,51 @@ to limit the serialization depth.
49
49
Just like other Symfony and API Platform components, the Serializer component can be configured using attributes, XML
50
50
or YAML. Since attributes are easy to understand, we will use them in the following examples.
51
51
52
-
Note: if you aren't using the API Platform distribution, you will need to enable annotation support in the serializer configuration:
52
+
> [!NOTE]
53
+
> If you are not using the API Platform distribution, you need to enable annotation support in the serializer
54
+
> configuration as outlined below, depending on your Symfony version.
55
+
56
+
#### Configuration for Symfony `<= 6.4`
57
+
58
+
##### General Case
59
+
60
+
Add the following configuration to your `framework.yaml` file:
53
61
54
62
```yaml
55
63
# api/config/packages/framework.yaml
56
64
framework:
57
65
serializer: { enable_annotations: true }
58
66
```
59
67
60
-
If you use [Symfony Flex](https://github.com/symfony/flex), just execute `composer req doctrine/annotations` and you are
61
-
all set!
68
+
##### Using Symfony Flex
69
+
70
+
If you use [Symfony Flex](https://github.com/symfony/flex) and Symfony `<= 6.4`, simply run the following command:
71
+
72
+
```console
73
+
composer req doctrine/annotations
74
+
```
75
+
76
+
You're all set!
77
+
78
+
#### Configuration for Symfony `>= 7.0`
79
+
80
+
If you are using Symfony >= 7.0, [annotations have been replaced by attributes](https://www.doctrine-project.org/2022/11/04/annotations-to-attributes.html).
81
+
82
+
Update your configuration as follows:
83
+
84
+
```diff
85
+
# api/config/packages/framework.yaml
86
+
87
+
framework:
88
+
- serializer: { enable_annotations: true }
89
+
+ serializer: { enable_attributes: true }
90
+
```
91
+
92
+
#### Additional Syntax Configuration for All Versions
93
+
94
+
If you want to use YAML or XML for serialization, add the mapping path to the serializer configuration:
62
95
63
-
If you want to use YAML or XML, please add the mapping path in the serializer configuration:
0 commit comments