Serialization
T3api uses JMS serializer to turn Extbase entities into JSON (serialization) and to turn JSON payload of POST, PUT and PATCH requests into entities (deserialization).
Serialization of a class can be configured in two ways:
- Annotations in the model class - the best option for models you own. T3api delivers its own set of annotations in namespace
\Source(Broker\ T3api\ Annotation\ Serializer Groups,Serialized,Name Virtual,Property Exclude,Read,Only Property Maxand types inDepth Type\*). - YAML metadata - for classes you can not change (e.g. models of 3rd party extensions or TYPO3 core). See Yaml metadata.
Both sources are merged, so you can mix them freely.
use SourceBroker\T3api\Annotation as T3api;
/**
* @T3api\ApiResource(
* collectionOperations={
* "get"={
* "path"="/items",
* "normalizationContext"={
* "groups"={"api_get_collection_item"}
* },
* },
* },
* )
*/
class Item extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @T3api\Serializer\Groups({"api_get_collection_item"})
*/
protected string $title = '';
/**
* @T3api\Serializer\VirtualProperty("titleLength")
* @T3api\Serializer\Groups({"api_get_collection_item"})
*/
public function getTitleLength(): int
{
return mb_strlen($this->title);
}
}
Copied!
Next pages describe:
- Context groups - how to decide which properties are returned by which operation.
- Handlers - built-in types for images, files, links and records, and how to write your own.
- Subscribers - listeners of serialization events (
@id,uid, cache tags, exceptions). - Yaml metadata - configuration of classes you do not own.
- Expression language - expression language in serialization.
- Exceptions - graceful handling of broken files.