Project

General

Profile

Actions

Bug #106638

open

Double json_encode when persisting an Extbase model property with database field type "JSON"

Added by Devid Messner 19 days ago. Updated 15 days ago.

Status:
Under Review
Priority:
Should have
Assignee:
Category:
Extbase
Target version:
-
Start date:
2025-04-30
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
13
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

When persisting an Extbase model with a property mapped to a database field of type JSON, the value gets double-encoded with json_encode.

Background: In typo3/cms-extbase/Classes/Persistence/Generic/Backend.php → persistObject(), all property values must either be strings or be converted to strings. This means an array or object must already be passed as a JSON string.
Additionally, in vendor/typo3/cms-core/Classes/Database/Connection.php → ensureDatabaseValueTypes(), the database field type is checked. If the type is json, the string is passed through json_encode again — specifically in vendor/doctrine/dbal/src/Types/JsonType.php → convertToDatabaseValue().
As a result, the field (TCA type json) is no longer recognized as valid JSON in the backend.

Workaround: Change the field type in the database from json to longtext.

Question: Is there a recommended solution or approach to preserve the use of the json field type?


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #99062: Native JSON field support in Doctrine DBALClosedBenni Mack2022-11-11

Actions
Actions #1

Updated by Stefan Bürk 19 days ago

  • Status changed from New to Accepted
  • Assignee set to Stefan Bürk

Extbase never had "json" support, and misses TCA type=json (DB type json) support.
At least the double encoding should be prevented in the first step and as "bugfix",
literally ignoring TCA/DB Type json for now.

In v14 support for extbase (DECODE + ENCODE) can be added in a dedicated step,
which is not really suitable as bugfix due to changes required for models I guess.

Actions #2

Updated by Gerrit Code Review 15 days ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89293

Actions #3

Updated by Gerrit Code Review 15 days ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89293

Actions #4

Updated by Stefan Bürk 15 days ago

  • Related to Feature #99062: Native JSON field support in Doctrine DBAL added
Actions #5

Updated by Gerrit Code Review 15 days ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89293

Actions #6

Updated by Gerrit Code Review 15 days ago

Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/89293

Actions

Also available in: Atom PDF