The same goes for encoding. The calling API is the same as before.

With json_serializable,
you can forget any manual JSON serialization in the User class.
The source code generator creates a file called user.g.dart,
that has all the necessary serialization logic.
You no longer have to write automated tests to ensure
that the serialization works—it’s now
the library’s responsibility to make sure the serialization works
appropriately.

Generating code for nested classes

You might have code that has nested classes within a class.
If that is the case, and you have tried to pass the class in JSON format
as an argument to a service (such as Firebase, for example),
you might have experienced an Invalid argument error.

Consider the following Address class:

The Address class is nested inside the User class: