#106638Double json_encode when persisting an Extbase model property with database field type "JSON"
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?
Reviews 5
- 14.3 94891[BUGFIX] Honor parameter types in writable Connection methods
- main 89293[BUGFIX] Honor parameter types in writable Connection methods
- 14.3 94189[TASK] Clarify what the storage tests actually verify
- main 94182[TASK] Clarify what the storage tests actually verify
- main 90957[WIP][!!!][TASK] Disable converting values by default in `Connection`