---
title: "Subscribers"
manual: "TYPO3 REST API"
version: "main"
permalink: "https://docs.typo3.org/permalink/sourcebroker/t3api:serialization-subscribers@main"
source: "Serialization/Subscribers/Index.rst"
rendered: "2026-12-02T13:26:39+00:00"
---

# Subscribers {#serialization-subscribers}

A subscriber is a class that listens to one or more events during the serialization
or deserialization process. These events can include pre-serialization, post-serialization,
pre-deserialization, and post-deserialization. Subscribers are used to customize
the serialization/deserialization process. For example, you might use a subscriber
to change the serialized representation of certain types of objects, or to perform
some custom logic before an object is serialized.

Subscribers are registered in `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers']`.
Each of them has to implement `\JMS\Serializer\EventDispatcher\EventSubscriberInterface`.
To add your own subscriber add it in [`ext_localconf.php`](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ExtensionArchitecture/FileStructure/ExtLocalconf.html#file-extension-ext-localconf-php) of your extension:

```php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'][] = \Vendor\Extension\Serializer\Subscriber\MySubscriber::class;
```

Here is a list of built-in T3api subscribers.

## AbstractEntitySubscriber {#serialization-subscribers-abstract-entity-subscriber}

This subscriber listens to the `POST_SERIALIZE` and `PRE_DESERIALIZE` events. In the case
of the `POST_SERIALIZE` event, it adds additional properties (defined in `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['forceEntityProperties']`, by default `uid`)
and IRI (`@id`) to the serialized object if the object is an instance of `AbstractDomainObject`.
IRI is added only if the class is an API resource with an item operation.
In the case of the `PRE_DESERIALIZE` event, it changes the type of nested entities to a custom one to enable
data handling with a serializer handler (so related records can be passed in payload as `uid` or as an object).

## CacheTagSubscriber {#serialization-subscribers-cache-tag-subscriber}

This subscriber listens to the `POST_SERIALIZE` event. For every serialized `AbstractDomainObject`
it collects cache tags `<table>` and `<table>_<uid>` (e.g. `tx_news_domain_model_news_1`).
Tags are used by [response cache](https://docs.typo3.org/permalink/sourcebroker/t3api:response-cache@main) to invalidate cached responses when a record is changed.
Tags are collected only while response cache is collecting (otherwise the subscriber does nothing).

## CurrentFeUserSubscriber {#serialization-subscribers-current-fe-user-subscriber}

This subscriber listens to the `PRE_SERIALIZE` and `PRE_DESERIALIZE` events.
On `PRE_SERIALIZE`, it replaces `CurrentFeUserHandler::TYPE` with the configured frontend user model class.
On `PRE_DESERIALIZE`, it makes sure that `CurrentFeUserHandler` is called for every property of this type,
so the currently logged in frontend user is attached to the incoming data.
Serialized names defined in annotations and YAML metadata are respected, and serialization groups
and property exclusions determine which properties are processed.
Look for more info at [current user assignment use case](https://docs.typo3.org/permalink/sourcebroker/t3api:use-cases-current-user-assignment@main).

## FileReferenceSubscriber {#serialization-subscribers-file-reference-subscriber}

This subscriber listens to the `PRE_SERIALIZE` and `PRE_DESERIALIZE` events.
In both cases, if the type is a subclass of `FileReference` or `Folder` (on deserialization also `File` and its subclasses) and it is nested in another object, it changes the type to a custom one
to enable data handling with `FileReferenceHandler` (see [FileReference](https://docs.typo3.org/permalink/sourcebroker/t3api:serialization-handlers-file-reference@main)).

## FileTokenSubscriber {#serialization-subscribers-file-token-subscriber}

This subscriber listens to the `POST_SERIALIZE` event. It adds `fileToken` to files (`sys_file`) which can be
referenced in the next request, see [File token](https://docs.typo3.org/permalink/sourcebroker/t3api:handling-file-upload-file-token@main).

## GenerateMetadataSubscriber {#serialization-subscribers-generate-metadata-subscriber}

This subscriber listens to the `PRE_SERIALIZE` and `PRE_DESERIALIZE` events.
In both cases, it generates YAML serializer metadata (merged from annotations and [YAML metadata](https://docs.typo3.org/permalink/sourcebroker/t3api:serialization-yaml-metadata@main))
and caches it in `var/cache/code/t3api/jms-metadir`.
Data from `var/cache/code/t3api/jms-metadir` is later used to serialize/deserialize by JMS serializer.

## ResourceTypeSubscriber {#serialization-subscribers-resource-type-subscriber}

This subscriber listens to the `POST_SERIALIZE` event. It adds the resource type (`@type`)
to the serialized object if the object is an instance of `AbstractDomainObject`.
Value is the fully qualified class name, e.g. `SourceBroker\\T3apinews\\Domain\\Model\\News`. Adding
`@type` is not activated by default as it can take a lot of space in the response.
To activate it add in your local extension [`ext_localconf.php`](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ExtensionArchitecture/FileStructure/ExtLocalconf.html#file-extension-ext-localconf-php):

```php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'][] = \SourceBroker\T3api\Serializer\Subscriber\ResourceTypeSubscriber::class;
```

## ThrowableSubscriber {#serialization-subscribers-throwable-subscriber}

This subscriber listens to the `POST_SERIALIZE` event. If the object is an instance of `Throwable`, it adds
`hydra:description` (exception message) and - in `Development` application context only - `hydra:debug` (stack trace)
to the serialized object.

Unexpected exceptions (not implementing `SourceBroker\T3api\Exception\ExceptionInterface`) are logged with an event ID
and result in HTTP 500. Outside of `Development` application context the response contains a generic
`SourceBroker\T3api\Exception\InternalServerErrorException` with this event ID instead of the original exception, so its
message is not returned to the client. Use the event ID to find the original exception in the TYPO3 log.
