Flutter

JSON Serialization

json_serializable, fromJson/toJson, code generation, nested JSON, custom converters

20 câu hỏi phỏng vấn·
Mid-Level
1

Which Flutter package is commonly used for automatic JSON serialization code generation?

Câu trả lời

The json_serializable package automatically generates fromJson and toJson serialization code from annotations. It works with build_runner to analyze annotations and generate the corresponding .g.dart file, reducing boilerplate code and manual errors.

2

Which annotation must be placed on a class to enable json_serializable code generation?

Câu trả lời

The @JsonSerializable() annotation tells build_runner that this class should have serialization code automatically generated. It is placed just before the class declaration and can accept optional parameters to customize serialization behavior.

3

Which command to run to generate serialization code with build_runner?

Câu trả lời

The command flutter pub run build_runner build triggers code generation for all annotated files. The --delete-conflicting-outputs option removes existing generated files before creating new ones, avoiding version conflicts.

4

Which file is generated by json_serializable for a User class defined in user.dart?

5

Which Dart directive links the generated .g.dart file to the source class?

+17 câu hỏi phỏng vấn

Nắm vững Flutter cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí