From 67a00d0c0a2820d78285291a9822a2edc84f925c Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Tue, 1 Mar 2016 10:13:48 +0200 Subject: [PATCH 1/7] Add information about JsonSerializableNormalizer --- components/serializer.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/serializer.rst b/components/serializer.rst index f72d4e91638..6d9c97ac03b 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -511,6 +511,18 @@ There are several types of normalizers available: Objects are normalized to a map of property names to property values. +::class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` + This normalizer works with classes that implement `\JsonSerializable`. + + It will call the `jsonSerialize` method and then further normalize the result. + This means that nested `JsonSerializable` classes will also be normalized. + + This normalizer is particularly helpful when you want to gradually migrate + from an existing codebase using simple `json_encode` to the full Symfony + Serializer by allowing you to mix which normalizers are used for which classes. + + Unlike with `json_encode` circular references are handled. + Handling Circular References ---------------------------- From 99aa80a8694181acaa1c23183e240154b807d37b Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Tue, 1 Mar 2016 10:19:15 +0200 Subject: [PATCH 2/7] Add information for DateTimeNormalizer --- components/serializer.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/serializer.rst b/components/serializer.rst index 6d9c97ac03b..45455ee8b7e 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -523,6 +523,10 @@ There are several types of normalizers available: Unlike with `json_encode` circular references are handled. +::class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` + This normalizer converts \DateTime objects (or anything that implements + `\DateTimeInterface`) into strings. By default it uses the RFC3339 format. + Handling Circular References ---------------------------- From dfd81431e6b8f1d9092d404d383ae0f96710da5b Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Tue, 1 Mar 2016 10:19:26 +0200 Subject: [PATCH 3/7] Add information for the DataUriNormalizer --- components/serializer.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/serializer.rst b/components/serializer.rst index 45455ee8b7e..1070f18ccdc 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -527,6 +527,10 @@ There are several types of normalizers available: This normalizer converts \DateTime objects (or anything that implements `\DateTimeInterface`) into strings. By default it uses the RFC3339 format. +::class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` + This normalizer converts \SplFileInfo objects into a data URI string + (`data:...`) such that files can be embedded into serialized data. + Handling Circular References ---------------------------- From d20a80f22916ff1f48d59d3fbd80badb7ef02e05 Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Tue, 1 Mar 2016 23:37:20 +0200 Subject: [PATCH 4/7] Double backticks for code --- components/serializer.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/serializer.rst b/components/serializer.rst index 1070f18ccdc..02884b2ccde 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -512,24 +512,24 @@ There are several types of normalizers available: Objects are normalized to a map of property names to property values. ::class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` - This normalizer works with classes that implement `\JsonSerializable`. + This normalizer works with classes that implement ``\JsonSerializable``. - It will call the `jsonSerialize` method and then further normalize the result. - This means that nested `JsonSerializable` classes will also be normalized. + It will call the ``jsonSerialize`` method and then further normalize the result. + This means that nested ``JsonSerializable`` classes will also be normalized. This normalizer is particularly helpful when you want to gradually migrate - from an existing codebase using simple `json_encode` to the full Symfony + from an existing codebase using simple ``json_encode`` to the full Symfony Serializer by allowing you to mix which normalizers are used for which classes. - Unlike with `json_encode` circular references are handled. + Unlike with ``json_encode`` circular references are handled. ::class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` - This normalizer converts \DateTime objects (or anything that implements - `\DateTimeInterface`) into strings. By default it uses the RFC3339 format. + This normalizer converts ``\DateTime`` objects (or anything that implements + ``\DateTimeInterface``) into strings. By default it uses the RFC3339 format. ::class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` - This normalizer converts \SplFileInfo objects into a data URI string - (`data:...`) such that files can be embedded into serialized data. + This normalizer converts ``\SplFileInfo`` objects into a data URI string + (``data:...``) such that files can be embedded into serialized data. Handling Circular References ---------------------------- From 85add134748acf2b060a59fcd3e134dd4ff98207 Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Wed, 2 Mar 2016 10:10:51 +0200 Subject: [PATCH 5/7] Add links to php docs --- components/serializer.rst | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/components/serializer.rst b/components/serializer.rst index 02884b2ccde..b2b585e5bfd 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -511,25 +511,27 @@ There are several types of normalizers available: Objects are normalized to a map of property names to property values. -::class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` - This normalizer works with classes that implement ``\JsonSerializable``. +:class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer` + This normalizer works with classes that implement :phpclass:`JsonSerializable`. - It will call the ``jsonSerialize`` method and then further normalize the result. - This means that nested ``JsonSerializable`` classes will also be normalized. + It will call the :phpmethod:`JsonSerializable::jsonSerialize` method and + then further normalize the result. This means that nested + :phpclass:`JsonSerializable` classes will also be normalized. This normalizer is particularly helpful when you want to gradually migrate - from an existing codebase using simple ``json_encode`` to the full Symfony + from an existing codebase using simple :phpfunction:`json_encode` to the Symfony Serializer by allowing you to mix which normalizers are used for which classes. - Unlike with ``json_encode`` circular references are handled. + Unlike with :phpfunction:`json_encode` circular references can be handled. -::class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` - This normalizer converts ``\DateTime`` objects (or anything that implements - ``\DateTimeInterface``) into strings. By default it uses the RFC3339 format. +:class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` + This normalizer converts :phpclass:`DateTimeInterface` objects (e.g. + :phpclass:`DateTime` and :phpclass:`DateTimeImmutable`) into strings. + By default it uses the RFC3339 format. -::class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` - This normalizer converts ``\SplFileInfo`` objects into a data URI string - (``data:...``) such that files can be embedded into serialized data. +:class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` + This normalizer converts :phpclass:`SplFileInfo` objects into a data URI + string (``data:...``) such that files can be embedded into serialized data. Handling Circular References ---------------------------- From c4432a66d6a68d803a4af97896eaf7274d011d90 Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Sat, 5 Mar 2016 17:05:15 +0200 Subject: [PATCH 6/7] Add a link to RFC3339 Linked direct to the example section as its probably most helpful --- components/serializer.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/serializer.rst b/components/serializer.rst index b2b585e5bfd..0a9644c5c96 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -527,7 +527,7 @@ There are several types of normalizers available: :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` This normalizer converts :phpclass:`DateTimeInterface` objects (e.g. :phpclass:`DateTime` and :phpclass:`DateTimeImmutable`) into strings. - By default it uses the RFC3339 format. + By default it uses the RFC3339_ format. :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` This normalizer converts :phpclass:`SplFileInfo` objects into a data URI @@ -675,3 +675,4 @@ you indicate that you're expecting an array instead of a single object. .. _`JMS serializer`: https://github.com/schmittjoh/serializer .. _Packagist: https://packagist.org/packages/symfony/serializer +.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8 From 79245afaa0c6f3a45ac161a9ee8d16820e8e9e8a Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Sat, 5 Mar 2016 17:09:58 +0200 Subject: [PATCH 7/7] Add versionadded --- components/serializer.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/serializer.rst b/components/serializer.rst index 0a9644c5c96..d8ec54f7e92 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -533,6 +533,10 @@ There are several types of normalizers available: This normalizer converts :phpclass:`SplFileInfo` objects into a data URI string (``data:...``) such that files can be embedded into serialized data. +.. versionadded:: 3.1 + The ``JsonSerializableNormalizer``, ``DateTimeNormalizer`` and + ``DataUriNormalizer`` normalizers were added in Symfony 3.1 + Handling Circular References ----------------------------