Greetings All,

“Serialization is a concept in EmberJS which gives us the facility to overload the payload data format before it sends to the server”.

Welcome back!  I am Ashutosh and this blog is in continuation of my previous blog which was about the normalization, a concept in ember which facilitates overriding payload format after data received from the server. After completion of both parts, you will be able to use EmberJS in those applications as well where the backend API has been already written.

Prerequisites: Pre requisites will be the same as it was in part one. Let’s do something exciting. Also, I am assuming you are here after reading part-1. If not then have a look, please.

Let’s try to look the following code section which contains code to send a post request to the server in order to save a new product.

Above code will send the product payload data on URL http://localhost:4200/product/create with the post request to save a new product. The payload data format which sends by above code will look like following:

Above data format is in JSON API standard. But, our server expects data in a format that looks like following:

Here, both are in the different format it means we will not be able to save our product on the server. No, it does not look like that because here comes Serialization, gives us the facility to sends data in the desired format.

Have you remembered the part-1 of this blog where we generated the sterilizers using ember-cli in our application? If yes, then in the same file i.e. app/serializers/product.js, we are going to override another method named as serialize(). This method contains a list of arguments which can be used if we want more customization.

Let’s have a look how to override the serialize() method:

A big congratulation to you as you have finished successfully both the parts. Now you can easily customize or overload payload data according to your requirement. But my recommendation is, override payloads one only when if your backend APIs has already written. Otherwise, It’s a good practice to follow the standards.

On the time of writing this blog, only a few frameworks are following JSON API standard and obviously, EmberJS is one of them. As JSON API standard in a new concept and it’s getting popular, we hope, in future, it will be implemented as a global.

Thanking you all,

Please tell your interest by playing with the keyboard in our comment box. Any type of feedback will be really appreciated.

Hope to see you soon, until then Happy Learning…….  🙂 🙂