Active Model Serializer vs Fast JSON API Serializer

Rajaa Boulassouak
3 min readDec 2, 2018

--

After trying out Netflix’s Fast JSON API Serializer for the first time with Ruby on Rails I would like to point out some of its differences to Active Model Serializer (AMS). I have used the same project once for both, first using AMS and the second time using Fast JSON API.

Define serializer for a ressource:

using AMS the CustomerSerializer class inherits from ActiveModel::Serializer to apply expected behavior.

where when using Fast JSON API the FastJsonapi::ObjectSerializer is included in the CustomerSerializer instead of inheriting from the base gem. Also there is no :id key required in the attributes, because the fast_json_api gem requires the :id by default on any object that is passed through initialization.

In controller:

When using AMS by default the controller uses the serializer that matches the object class.

When using Fast JSON API the serializer to use needs to be specifically defined in the controller and the new instance of the serializer class gets passed the result that is to be rendered as an argument.

Resource presentation:

this is how the outcome from the code above looks like using AMS

and this how the outcome looks like using Fast JSON API. Compared to AMS, Fast JSON API exposes more information allowing to recognize a resource just by the response contents. More about Fast JSON API document structures here.

Performance:

Fast JSON API performance tests indicate a 25x speed gain over AMS.

You can run the benchmark tests for yourself. Refer to this readme.

Overall I found Fast JSON API the better solution to use with Ruby on Rails. It’s a great response standard that can save time. A main reason why I prefer using Fast JSON API over AMS is that AMS’s latest update has been about two years ago.

--

--