I am developing my first mobile app with Flutter and I have a doubt.
Suppose the app receives a JSON like this:
{
"_id": "123",
"name": "X",
}
To receive it and send it the following model would be created:
class User {
String id;
String name;
User({
this.id,
this.name
});
factory User.fromJson(Map<String, dynamic> json) => User(
id: json["_id"],
name: json["name"]
);
Map<String, dynamic> toJson() => {
"_id": id,
"name": name
};
}
Now for some reason I need to change the model structure of that data to, for example:
{
"id": "123",
"info": {
"name":"X",
"age":"20"
}
}
In the database there are objects stored with the old structure and, when the app receives them, there will be an error because the new model does not match the old data.
If the app is already in production, what is the most common way to avoid this error without affecting the users?
There are countless versioning ideas and frameworks out there, but the basics are:
OR:
The first is more user friendly and easier to handle, since you can work and deploy asynchronously. You can for example deploy the new backend first, while waiting for app store approval of the new app.