When to use Serializers?
Define Serializer
Serialisation (I’ll use s in writing about the concept, and z when discussing the thing itself) in programming is about converting the state of an object into something that can be stored or transferred. When you really want to serialise the state of an application to disk, you probably want full, unmodified serialisation, so the question about serialisation typically comes up when you want to share data with external parties. To these parties you don’t want to share the raw data, but pre-process it a bit, perhaps convert the internal state to objects that are more generic and don’t expose the full internals. In such case you might want to consider introducing the concept of Serializers.
Alternatives to using serializers
Before introducing new tooling, always consider the following default options Rails offers:
- Serializers live on the view-layer. The default approach rails suggests is to have e.g.
{index, show}.json.jbuilderfiles in your v…