Skip to content
tezvyn:

Top 30 Serialization Interview Questions and Answers

30 multiple-choice questions on Serialization, drawn from 30 bites out of the 33 tagged Serialization on Tezvyn. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.

30 questions. Pick an answer, or open “Show the answer” to read it.

Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.

  1. Question 1 of 30

    What mechanism triggers FastAPI to automatically validate and parse an incoming JSON request body against a schema?

    Show the answer

    Answer: b · Using a Pydantic model as the type hint for a route parameter

    FastAPI inspects function signature type hints at runtime, so using a Pydantic model as a parameter type hint automatically triggers request parsing and validation. Manually calling json.loads inside the route is a red flag that ignores this declarative mechanism, and response_model governs response serialization, not request validation.

    Read the full bite: How does FastAPI leverage Pydantic for request validation and serialization?

  2. Question 2 of 30

    You need to parse a dynamic JSON array into List<Product> where some objects may contain missing or mistyped fields. Which approach best preserves type safety and prevents runtime crashes?

    Show the answer

    Answer: a · Use a factory constructor that checks runtime types and defaults, then map over the list while isolating or skipping invalid rows.

    Defensive parsing inside a factory constructor centralizes validation and runtime type checks in the model layer, while isolating or skipping invalid rows during mapping prevents one malformed item from crashing the entire list. Option C spreads uncertainty by pushing null handling into the UI, and C fails because a Map cannot be directly cast to a custom class.

    Read the full bite: How do you model Product and safely parse JSON into List<Product>?

  3. Question 3 of 30

    Which is the strongest reason to prefer a string enum over a numeric enum for a status field returned by an external API?

    Show the answer

    Answer: a · String enums use human-readable runtime values that match the API wire format exactly, avoiding an extra mapping layer.

    String enums let you assign API response values directly because their runtime values are the exact strings on the wire, unlike numeric enums which produce opaque integers and require a separate mapping. The most tempting distractor claims string enums offer reverse mapping, but that is actually a feature of numeric enums and is usually irrelevant for external API contracts.

    Read the full bite: How would you use an enum to represent API statuses?

  4. Question 4 of 30

    A FastAPI endpoint returns a UserDB model containing password_hash. Which strategy best prevents exposing the hash while keeping the API contract explicit and maintainable?

    Show the answer

    Answer: c · Create a separate UserOut model without password_hash and set response_model=UserOut on the endpoint.

    A dedicated output model declaratively isolates the API contract from the database schema and prevents accidental leaks if new sensitive fields are added later. Option B is a tempting quick fix, but it keeps the sensitive field in the source model and hides the contract outside the type system, making it harder to maintain.

    Read the full bite: How do you prevent password_hash from appearing in a FastAPI response?

  5. Question 5 of 30

    What happens to extra fields on an object returned by a FastAPI endpoint when a response_model is declared?

    Show the answer

    Answer: b · FastAPI silently filters out fields not present in the response_model during serialization

    The card explains that FastAPI automatically drops undeclared fields when serializing against the response_model. Option C represents the brittle manual approach the card explicitly warns against, whereas the response_model is designed to handle filtering for you.

    Read the full bite: How would you use a Pydantic response_model to enforce output structure?

  6. Question 6 of 30

    What is the primary purpose of using a Pydantic @computed_field?

    Show the answer

    Answer: b · To automatically include a value derived from other fields in the model's serialized output.

    A computed field promotes a derived value to be part of the model's exportable data, automatically including it in the serialized output. It is not for defining fundamental inputs, which should be regular Pydantic fields.

    Read the full bite: Pydantic Computed Fields: Serialize Derived Values

  7. Question 7 of 30

    What is the primary reason JSON is widely adopted for data exchange in web APIs?

    Show the answer

    Answer: b · It provides a human-readable, text-based format for structured data that is easily parsed by various programming languages.

    JSON's main advantage is its simple, text-based, and human-readable structure, which allows different systems and programming languages to easily exchange and parse structured data. It is not a binary format, nor does it execute code, and it explicitly lacks support for comments.

    Read the full bite: JSON: The Lingua Franca of Web APIs

  8. Question 8 of 30

    When evaluating manual JSON serialization against json_serializable for a growing Dart codebase, which trade-off is most accurate?

    Show the answer

    Answer: d · Manual serialization avoids build dependencies but risks boilerplate drift, whereas code generation adds compile-time latency while producing equivalent runtime performance.

    Option D captures the core trade-off: manual methods avoid build steps but become error-prone at scale, while json_serializable introduces build_runner latency but generates plain Dart that performs identically at runtime. Option A is a tempting distractor because many candidates mistakenly believe code generation affects end-user performance, but the card emphasizes runtime is identical.

    Read the full bite: Compare manual JSON serialization versus json_serializable

  9. Question 9 of 30

    When using Swift's Codable protocol, which scenario would typically require custom implementation beyond the default synthesis?

    Show the answer

    Answer: b · The JSON keys do not exactly match the Swift property names.

    Option B is correct because the card explicitly states that the default implementation will fail if JSON keys don't match Swift property names, requiring a custom CodingKeys enum. Option C is incorrect as Codable automatically handles nested Codable types.

    Read the full bite: Swift's Codable: Effortless JSON & Data Parsing

  10. Question 10 of 30

    You are using Kotlinx.serialization to parse JSON containing post_title into a Kotlin data class. Which approach follows best practices while correctly mapping the field?

    Show the answer

    Answer: c · Annotate the property with @SerialName("post_title") and keep it named postTitle

    Kotlinx.serialization uses @SerialName to map a JSON key to a camelCased Kotlin property without requiring custom serializers. Option B is tempting because it also uses an annotation, but @Json is Moshi's decorator, not Kotlinx.serialization's.

    Read the full bite: How do you configure Moshi or Kotlinx.serialization for JSON key mismatches?

  11. Question 11 of 30

    Which statement accurately contrasts JSON serialization approaches in Go and Rust?

    Show the answer

    Answer: c · Go's standard library includes a reflection-based JSON encoder, while Rust relies on external crates like serde to derive serialization traits at compile time.

    Go ships encoding/json in its standard library and uses runtime reflection, whereas Rust intentionally omits serialization from std and delegates to external crates like serde for compile-time derived traits. Distractor B is tempting because derive macros can look like reflection, but they generate code at compile time rather than inspecting types at runtime.

    Read the full bite: Serialize a Go struct to JSON and contrast with Rust

  12. Question 12 of 30

    When deserializing a sealed class hierarchy with Moshi using a JSON 'type' discriminator, which strategy is idiomatic and preserves compile-time type safety?

    Show the answer

    Answer: b · Register a JsonAdapter.Factory that peeks the discriminator and delegates to the correct adapter

    A JsonAdapter.Factory is the idiomatic Moshi pattern for discriminated polymorphism because it peeks the type key and delegates without reflection. Option D is tempting because @JsonClassDiscriminator is real, but it belongs to kotlinx.serialization, not Moshi, which lacks built-in sealed class support.

    Read the full bite: Parse polymorphic media JSON with Kotlin sealed classes and custom serializers

  13. Question 13 of 30

    Which approach correctly stores and retrieves a typed object in localStorage?

    Show the answer

    Answer: d · Use setItem with JSON.stringify, then getItem, check for null, parse in try-catch, and cast to an interface

    localStorage persists only strings, so you must stringify on write and parse on read, but you must also check for null before parsing because getItem returns null when a key is missing. Option C is tempting because it includes serialization and typing, yet skipping the null check causes a runtime error whenever the key does not exist.

    Read the full bite: How do you store and retrieve a TypeScript object in localStorage?

  14. Question 14 of 30

    Which task is the primary responsibility of JSONEncoder in a Swift application?

    Show the answer

    Answer: a · Converting Swift objects into a standardized JSON format for external use.

    JSONEncoder's fundamental purpose is to serialize Swift objects into JSON data, preparing them for tasks like sending to a server or saving to a file. It does not directly handle network transmission or the reverse process of parsing JSON.

    Read the full bite: JSONEncoder: Turning Swift Objects into JSON

  15. Question 15 of 30

    You pass a custom Dart object as an argument to invokeMethod and the native side cannot use it directly. Why?

    Show the answer

    Answer: a · The platform codec only serializes primitives and collections, not arbitrary classes

    The StandardMethodCodec supports null, primitives, strings, byte buffers, and Lists/Maps of those, so custom classes must be flattened to a Map first. Calls are also asynchronous, not synchronous as the first option claims.

    Read the full bite: MethodChannel data flow and type marshalling

  16. Question 16 of 30

    How should you move a large non-serializable native object to JS over the legacy bridge?

    Show the answer

    Answer: d · Pass an opaque handle or file URI and keep the object on the native side

    Keep the object native and reference it via an id or URI, avoiding serialization. Sending raw pointers or function references is not possible across the serialized bridge.

    Read the full bite: What data types cross the bridge, and their limits?

  17. Question 17 of 30

    What is a key characteristic that distinguishes Kotlinx.serialization from reflection-based serialization libraries?

    Show the answer

    Answer: b · It generates type-safe serialization code during compilation, avoiding runtime reflection.

    Kotlinx.serialization uses a compiler plugin to generate conversion logic at compile time, making it type-safe and performant without relying on runtime reflection. The most tempting distractor suggests it uses reflection, which is precisely what it aims to avoid.

    Read the full bite: Kotlinx.serialization: Kotlin's Native Data Converter

  18. Question 18 of 30

    When using `jsonDecode` from `dart:convert` on a JSON string representing a single object, what is the direct return type?

    Show the answer

    Answer: d · A Map<String, dynamic> containing the JSON data.

    The card states that `jsonDecode` typically results in a `Map<String, dynamic>` for JSON objects. It explicitly mentions that it does not return your custom class directly, which is a common misconception for beginners.

    Read the full bite: JSON in Dart: Using `dart:convert`

  19. Question 19 of 30

    Which of the following is a necessary step for Moshi to properly handle Kotlin data classes?

    Show the answer

    Answer: d · Providing a KotlinJsonAdapterFactory or using moshi-kotlin-codegen.

    Moshi requires either compile-time code generation via moshi-kotlin-codegen or a runtime reflection adapter (KotlinJsonAdapterFactory) to understand Kotlin's specific language features. Without this, it cannot correctly map JSON to Kotlin objects. Forcing all properties to be nullable (Option C) is incorrect; Moshi is designed to handle Kotlin's non-nullability.

    Read the full bite: Moshi: Modern JSON for Kotlin & Android

  20. Question 20 of 30

    When is manual JSON serialization using `fromJson` and `toJson` methods the most suitable approach?

    Show the answer

    Answer: b · When you need to quickly prototype a small application or process JSON with an unusual format.

    Option B is correct because the card states manual serialization is "perfect for small projects, quick prototypes, or when you need to handle oddly-structured JSON." Option D is incorrect as manual serialization is prone to runtime errors from misspelled keys, a problem code generation aims to solve.

    Read the full bite: Manual JSON Serialization with fromJson/toJson

  21. Question 21 of 30

    What is the primary function of the part 'my_file.g.dart'; directive in conjunction with json_serializable?

    Show the answer

    Answer: b · It links the main class file to the automatically generated serialization and deserialization functions.

    The 'part' directive is a Dart language feature that allows a file to include code from another file, making the generated serialization functions (like _YourClassFromJson) accessible to the main class. Option D is a tempting distractor because 'part' does relate to partial definitions, but it's for the generated code, not the json_annotation package itself.

    Read the full bite: json_serializable: Automating JSON in Dart

  22. Question 22 of 30

    When saving a JavaScript object to Web Storage (like localStorage), why is it necessary to use JSON.stringify()?

    Show the answer

    Answer: d · Because Web Storage APIs are designed to store only string data for both keys and values.

    The card explicitly states that Web Storage was designed to store only strings for both its keys and values, making JSON.stringify() essential to convert objects into this required string format. Option C is incorrect because JSON.stringify() does not encrypt data; the card warns against storing sensitive data due to XSS vulnerability, not that stringify protects it.

    Read the full bite: Storing Objects in Web Storage: The JSON Step

  23. Question 23 of 30

    What happens when JSON with a wrong-typed field is parsed into a plain Python dataclass versus a Pydantic BaseModel?

    Show the answer

    Answer: a · The dataclass stores the wrong type silently, while the BaseModel coerces or raises a ValidationError

    Dataclass type hints are not enforced at runtime, so a wrong type is stored silently, whereas Pydantic validates and either coerces valid inputs or raises ValidationError. That runtime validation is exactly why FastAPI relies on Pydantic.

    Read the full bite: Pydantic BaseModel vs dataclasses in FastAPI

  24. Question 24 of 30

    Which combination lets a Pydantic model accept camelCase input yet keep snake_case Python attributes and still emit camelCase output?

    Show the answer

    Answer: b · An alias_generator like to_camel with populate_by_name=True, serializing with by_alias=True

    An alias generator maps camelCase to snake_case fields, populate_by_name keeps the real names usable, and by_alias=True restores camelCase on output. Aliasing only input leaves responses in snake_case, and the other options abandon idiomatic Python or automation.

    Read the full bite: Mapping camelCase JSON to snake_case Pydantic fields

  25. Question 25 of 30

    How does a Pydantic @computed_field behave with respect to request input and response output?

    Show the answer

    Answer: c · It is excluded from input and validation but included in serialized output and the JSON schema

    A computed field is derived during serialization, so it is never expected as input yet appears in the response and the OpenAPI schema. A default-valued field, by contrast, is a real input field, which is the common confusion.

    Read the full bite: Pydantic computed fields in response models

  26. Question 26 of 30

    What is the correct pattern for storing a custom User object in shared_preferences?

    Show the answer

    Answer: d · Convert User to a Map with toJson, encode with jsonEncode, store with setString, then decode and reconstruct with User.fromJson.

    shared_preferences only supports primitives, so you must serialize the object to JSON via toJson/jsonEncode and reconstruct with fromJson after jsonDecode. Option A is tempting because it names the right APIs, but casting jsonDecode output directly to a custom class is invalid in Dart.

    Read the full bite: Persist a custom Dart object using shared_preferences

  27. Question 27 of 30

    Which approach correctly sends a Dart object as JSON in an HTTP POST request using Dart's http package?

    Show the answer

    Answer: a · Convert the object to a Map with toJson, encode the Map with jsonEncode, set the Content-Type header to application/json, and pass the resulting string as the body

    The correct approach explicitly serializes the Map to a JSON string with jsonEncode and sets the Content-Type header so the server can parse the payload. Option D is tempting because it includes toJson and the correct header, but passing the Map directly causes the http package to call toString, producing invalid JSON syntax.

    Read the full bite: Structure a POST request to send a Dart object as JSON

  28. Question 28 of 30

    What is a key advantage of using BasicMessageChannel over MethodChannel?

    Show the answer

    Answer: c · It allows for the serialization and deserialization of arbitrary custom Dart objects using a specific codec.

    BasicMessageChannel's primary advantage is its ability to handle custom data types through specialized codecs, enabling serialization of any Dart object. MethodChannel, in contrast, is simpler and more idiomatic for infrequent, basic request/response calls, not for complex custom data types or streaming.

    Read the full bite: BasicMessageChannel: A Coded Pipe to Native

  29. Question 29 of 30

    You need to pass a Pydantic model containing datetime fields as a plain dict to a library that internally calls json.dumps. Which approach is correct?

    Show the answer

    Answer: b · model.model_dump(mode='json')

    model.model_dump(mode='json') returns a dictionary with JSON-compatible values such as ISO-format strings for datetimes, which the library can then encode. model.model_dump_json is tempting because it mentions JSON, but it returns a serialized string rather than the plain dict the library expects.

    Read the full bite: Serialize Pydantic Models with model_dump

  30. Question 30 of 30

    How does Retrofit determine which converter factory to use for deserializing an API response?

    Show the answer

    Answer: c · It iterates through registered factories, using the first one that declares it can handle the service method's return type.

    The card states Retrofit iterates through its list of registered converter factories, asking each one if it can convert the target type, and the first one that says 'yes' gets the job. It does not try all factories until one succeeds, nor is it explicitly specified per method.

    Read the full bite: Retrofit Converters: Speaking Your API's Language

Could you explain these out loud?

That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon