Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 1.74 KB

serializer.md

File metadata and controls

42 lines (28 loc) · 1.74 KB

Serializer

Koalati makes use of the API Platform's serializer, which itself is built on top of Symfony's Serializer. This is what allows entities and other data models from being converted to JSON, JSON+LD, CSV, XML and many other formats - as well as the other way around.

Serialiation is used in many areas, such as Koalati's Web API and server-client updates.

However, there are a few Koalati-specific implementations for the serialization process, all of which will be outlined in this documentation.

Entity normalization extensions

For some entities, we want data that isn't contained in the entity itself to be added to the serialized data. For others, we may want to edit the serialized data.

Ex.: when serializing a comment, we want the URL of the author's avatar to be included, but this URL is not contained in the Comment or in User entity. This information can be generated by a storage service.

To do this, you may create an Entity Extension that implements the EntityExtensionInterface interface in the App\Serializer\EntityExtension namespace.

The supports() method defines if an entity is supported by this extension, and the extendNormalization() method allows you to edit the serialized data for this entity.

Every entity extension that supports a given entity will be used in the serialization process. There is no way to control the order in which multiple entity extensions will be executed.

Encrypted IDs

To follow suit with the rest of the application, every ID in serialized data will be encrypted using the roukmoute/hashids-bundle.

This is done automatically in AbstractNormalizerDecorator::normalize().