Devot Logo
Devot Logo
Arrow leftBack to blogs

Symfony Serializer: What Happens Between Request and Response

Ante C.3 min readAug 6, 2025Technology
Ante C.3 min read
Contents:
1. Intro
2. Serializer
Final thoughts

1. Intro

First, let’s clarify a bit how the Request/Response architecture works when using REST APIs (if you don’t know what this means – you might be in the wrong place 🙂).

A client sends a request like this:

The server receives the request… then ??? happens, and the server replies:

What’s this ??? part, you ask?

This is where Symfony Serializer comes in. The backend receives a JSON request from a mobile or frontend app. It converts that JSON into something it can understand – in our case, a PHP object.

Once the backend understands it, it can save it to the database (or do whatever the business logic dictates). If saving, the object gets an ID and some timestamps. Then the Serializer converts it back to JSON and returns it to the frontend/mobile app as a response — and boom 💥 the Request/Response cycle is complete.

2. Serializer

2.1 What the hell is it?

It’s a Symfony component (duh). We’ll show some cool thingies you can do with it.

Main features:

  • Object → JSON — serialize

  • JSON → Object — deserialize

  • Object → array — normalize

  • Array → Object — denormalize

  • Array → JSON — encode

  • JSON → array — decode

We’ll focus on the first two since they’re the most used ones for REST APIs.

2.2 How do I install and use it?

As always in PHP – install it via Composer:

Then use Symfony’s autowiring:

Or build it manually (not recommended for prod but useful for examples):

2.3 What about the other way around?

Let’s do a reverse example: deserialize JSON to a Genre class object.

JSON input:

PHP class:

Deserialization:

Simple, right? Best thing is – we can tweak it to our liking.

2.4 Groups

Groups help with:

  • controlling what properties to include during conversion

  • controlling what properties to validate (yep, Validator understands groups too!)

Say we have a User object like this:

When creating a user, we want to hash the password before saving, and not return the password to the frontend. Groups help us do that.

Let’s namespace our groups using the {object}:{action} format:

  • Use user:create for incoming data

  • Use user:read when returning data (without password)

2.5 Virtual Properties

Let’s say our frontend doesn’t want to concatenate first and last name — they want fullName as a separate field.

Be smart. Use a virtual property:

When serializing with the user:read group — you'll get fullName too!

Example 2: Book + Author listing

Book.php

Author.php

When serializing with group book:listing, you’ll get just: book id, name, and author name. Perfect for list views.

2.6 NameConverters

By default, Serializer uses property names as-is. So:

…become:

But if your frontend expects snake_case, use a name converter!

In your framework.yaml:

Now this:

…becomes:

You can also create your own custom NameConverter if needed.

2.7 Other formats

Of course, it’s not just JSON — it supports:

  • CSV

  • XML

  • YAML

  • and our queen 👑 — JSON

Feel free to explore the others on your own!

Final thoughts

As one of my favorite Symfony components, Serializer is both fast and versatile, yet easy to use. If you’re building an API, transforming data between formats, or just want cleaner code — you’ll love what it offers.

Don’t skip it. It does too much heavy lifting to be ignored.

Spread the word:
Keep readingSimilar blogs for further insights
Guide to Microsoft Outlook Mail Integration Using Microsoft Graph API
Technology
Tomislav B.5 min readJul 29, 2025
Guide to Microsoft Outlook Mail Integration Using Microsoft Graph APIInsider roadmap to seamless Outlook Mail integration in Java and Spring Boot—unlocking Microsoft Graph API–powered app registration, secure authentication, and end-to-end email retrieval and delivery.
GitHub vs GitLab: Choosing the Right Platform for Your Development Workflow
Technology
Marko M.4 min readJul 23, 2025
GitHub vs GitLab: Choosing the Right Platform for Your Development WorkflowHead-to-head showdown between GitHub’s vast ecosystem and GitLab’s all-in-one DevOps powerhouse, revealing differences in repo management, CI/CD pipelines, security features, pricing, project-size suitability, and cutting-edge AI tools.
How to Integrate Microsoft Outlook Calendar into Your Spring Boot Application
Technology
Tomislav B.3 min readJul 17, 2025
How to Integrate Microsoft Outlook Calendar into Your Spring Boot ApplicationA step-by-step tutorial showing you how to: register a Spring Boot app in the Microsoft Entra admin center; add Graph SDK dependencies; set up DeviceCodeCredential for user authentication; fetch calendar events using start/end filters; and programmatically create new Outlook Calendar events via Microsoft Graph API.