Technical Senior Level

How does the Symfony Serializer work? Explain the difference between normalizers and encoders, and how you handle circular references and nested objects.

Quick Tip

Show the layers: "Normalizers turn objects into arrays, encoders turn arrays into JSON. I use serialization groups to expose different fields for list versus detail endpoints, and a circular reference handler that returns the entity ID."

What good answers include

The Serializer converts objects to arrays (normalization) then arrays to formats like JSON/XML (encoding), and vice versa. Normalizers handle the object-to-array step: ObjectNormalizer uses getters/setters, PropertyNormalizer accesses properties directly. Encoders handle array-to-format: JsonEncoder, XmlEncoder, CsvEncoder. Circular references: configure a handler (typically returning the ID) via the circular_reference_handler context option. Serialization groups (#[Groups]) control which properties are included in different contexts (list vs detail). Strong candidates discuss: custom normalizers for complex transformations, max depth handling for nested objects, DTO serialization for decoupling API responses from entities, and the name converter for snake_case to camelCase mapping.

What interviewers are looking for

Tests deep Symfony knowledge. Candidates who JSON-encode entities manually or who struggle with circular references do not understand the Serializer. Those who use groups, custom normalizers, and DTOs build clean APIs.

← All Symfony questions