What is Serialization? Including Django Rest Framework Example

Ryo Yamamoto
2 min readFeb 24, 2021

--

According to Wikipedia,

Serialization is the process of translating a data structure or object state into a format that can be stored (for example, in a file or memory data buffer) or transmitted (for example, across a computer network) and reconstructed later (possibly in a different computer environment).

If you understand it, you don’t need to read this article. Otherwise, for people who don’t understand(including me), the image below will be easier to understand which is describing the structure of serialization.

Django Serializer vs Django Rest Framework Serializer

When I create a Django App, I faced this question, and probably there are some people who are wondering about the same question. As you see below, there are two types of Serializer in Django. I’ll explain it quickly.

# Django Serializer
from django.core import serializers
# Django Rest Framework Serializer
from rest_framework import serializers

Django Serializer will serialize the entire model instances into JSON, XML, and so on. They don’t do anything besides just serializing.

Django Rest Framework Serializer will convert model instances into JSON when dealing with data from HTML forms or API requests.

Example 1: ModelSerializer(Django Rest Framework Serializer)

ModelSerializer is a default serializer that will automatically create a serializer for a model in Django.

--

--

Ryo Yamamoto
Ryo Yamamoto

No responses yet