Feature: #101404 - Extbase maps JSON fields to array properties
See forge#101404
Description
Extbase now maps database columns configured as TCA type
json
to domain model properties typed as
array
or
?array
. The JSON stored in the database is decoded into a PHP array
when the entity is reconstituted and an array is encoded as JSON when the
entity is persisted.
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class Product extends AbstractEntity
{
protected array $attributes = [];
protected ?array $metadata = null;
// getters and setters
}
return [
'columns' => [
'attributes' => [
'config' => [
'type' => 'json',
'default' => '[]',
],
],
'metadata' => [
'config' => [
'type' => 'json',
],
],
],
];
An empty database value and JSON that does not decode to an array leave a
non-nullable property at its default value and set a nullable property to
null
. A nullable property set to
null
is stored as
NULL
.
JSON objects are decoded into associative arrays, so an empty object
{} is written back as
[]
on the next persist.
Impact
Array properties of Extbase domain models can be used with TCA type
json
columns without a custom
Type value object.
Mapping such properties from request arguments (property mapping) and query
constraints on JSON columns are not part of this feature.
Array properties that map to other column types are still not populated from the database.