Please check your agent type and version and read on or switch to the right documentation.
Serializing your records
To be interpreted correctly by the ForestAdmin UI, the data must be sent from your admin backend using a particular structure.
This structure needs to comply to the JSON API standard. The JSON API standard is used to ensure a standardized way to format JSON responses returned to clients. You can find some more information directly from their website.
Most of the time, your admin backend will handle this for you, and you will not have to play with serialization. However you might encounter specific use cases that will require you to serialize data yourself, such as smart collections for example.
In order to help you do so, the helper RecordSerializer is made available through the packages built-in your admin panel.
To make use of the serializer, simply get it from your agent package, and initialize it with a collection of yours. The serializer will retrieve the structure of the collection, and thus, will know which attributes it needs to take in to perform the serialization.1
The serializer exposes a .serialize() method that takes as an argument an array of objects (or a single object). In the smart collection example, this array would be as such:
This is the proper format expected by the UI to correctly display the records.
Example 2 - Smart collection example with an added belongsTo relationship
Now let's say we want to reference the customer related to a stat instead of just displaying its email. We would then adapt the smart collection definition to include a field customer referencing the customers collection:
For the belongsTo relationship to be properly serialized, the records passed on to the serializer should include the related object (here customer), following this structure:
Now if we try to serialize this data, the serializer will automatically detect that the records to be serialized include another record (customer in this case), based on the collection definition.
The included records will then be picked up and wrapped to comply to the JSON API relationships format.
Note that the customer relationship is clearly indicated under the relationships attribute. Also note that the customer is automatically wrapped in the included section, with its attributes if you specified some (only id in this case).