Issue Bug Closed

#92473TYPO3\CMS\Core\Http\JsonReponse dont allow JsonSerializable and others

Daniel Kern 10/02/20, 13:56 updated 06/17/24, 22:26

Description

*Issue:*
I use TYPO3\CMS\Core\Http\JsonReponse in Middlewares. The constructor allow $data to be mixed. Even the internal function allows $data to be of any type. But between __construct and jsonEncode is another function setPayload wich only allows $data to be type of array. This results in the fact, that we can only respond arrays as JSON. But at least classes implementing @JsonSerializablev should be able to be responded too. Also, why isn’t it possible to return other types as JSON too?

*Solution:*
Remove the type annotation of setPayload. There would be no harm, because jsonEncode already checks for conversion errors. This should also not break anything.

*Before:*
@public function setPayload(array $data = [], $encodingOptions = self::DEFAULT_JSON_FLAGS): JsonResponse@

*After:*
@public function setPayload($data = [], $encodingOptions = self::DEFAULT_JSON_FLAGS): JsonResponse@

Reviews 1

History 56

  1. Daniel Kern changed subject TYPO3\CMS\Core\Http\JsonReponse dont allow JsonSerializable TYPO3\CMS\Core\Http\JsonReponse dont allow JsonSerializable and others Complexity easy no-brainer 10/02/20, 13:58

  2. Gerrit Code Review pushed patch set 1 for master to change 66016 status New Under Review 10/05/20, 19:40

  3. Christian Kuhn changed status Under Review New 10/20/21, 01:16

  4. Mathias Schreiber changed Sprint Focus Remote Sprint 03/08/22, 12:09

  5. Susanne Moog changed Complexity no-brainer medium 04/04/22, 08:34

  6. Benni Mack commented and changed status New Closed 06/17/24, 22:26

    Closing this issue (see the corresponding review) as this is not the job of the JsonResponse.