Project

General

Profile

Actions

Bug #95396

closed

JsonView missing support for DateTimeImmutable

Added by Oliver Eglseder about 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
Start date:
2021-09-29
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
no-brainer
Is Regression:
Sprint Focus:

Description

JsonView does "support" DateTime, because it automatically transforms it by formatting to ATOM.
The variant DateTimeImmutable is not formatted as ATOM, instead its properties will be listed. (offset and timestamp).

Controller code:

    public function listAction(): void
    {
        if ($this->view instanceof JsonView) {
            $this->view->setVariablesToRender(['publications']);
            $this->view->setConfiguration(
                [
                    'publications' => [
                        '_descendAll' => [
                            '_only' => [
                                'publishingDate',
                            ],
                            '_descend' => [
                                'publishingDate' => [],
                            ],
                        ],
                    ],
                ]
            );
        }
        $this->view->assign('publications', $this->publicationRepository->findAll());
    }

Actual:

[
  {
    "publishingDate": {
      "offset": 0,
      "timestamp": 1631119140
    }
  }
]

Expected:

[
  {
    "publishingDate": "2021-09-08T16:39:00+00:00" 
  }
]

Actions

Also available in: Atom PDF