Skip to content

Commit 31c670c

Browse files
committed
minor #22204 [JsonStreamer] Document DateInterval value object support (lacatoire)
This PR was merged into the 8.1 branch. Discussion ---------- [JsonStreamer] Document DateInterval value object support Fixes #22203 Document the `DateInterval` value object support added in symfony/symfony#63742. Commits ------- 9a0b34d [JsonStreamer] Document DateInterval value object support
2 parents c9fdfb1 + 9a0b34d commit 31c670c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

serializer/streaming_json.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,29 @@ traversing the object's properties::
730730

731731
.. note::
732732

733-
``DateTimeInterface`` objects are now handled as value objects internally.
734-
The previous ``DateTimeToStringValueTransformer`` and
733+
``DateTimeInterface`` and ``DateInterval`` objects are handled as value objects
734+
internally. The previous ``DateTimeToStringValueTransformer`` and
735735
``StringToDateTimeValueTransformer`` are deprecated in favor of
736736
``DateTimeValueObjectTransformer``.
737737

738+
``DateInterval`` objects are serialized to ISO 8601 duration strings
739+
(e.g. ``P2Y6M1DT12H30M5S``) and deserialized back using the
740+
``DateIntervalValueObjectTransformer``. You can customize the format
741+
using the ``date_interval_format`` option::
742+
743+
use App\Dto\Task;
744+
use Symfony\Component\TypeInfo\Type;
745+
746+
// ...
747+
748+
$json = $jsonStreamWriter->write($task, Type::object(Task::class), [
749+
'date_interval_format' => 'P%yY%mM%dDT%hH%iM%sS',
750+
]);
751+
752+
.. versionadded:: 8.1
753+
754+
``DateInterval`` value object support was introduced in Symfony 8.1.
755+
738756
Configuring Keys and Values Dynamically
739757
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
740758

0 commit comments

Comments
 (0)