For example, suppose I have some mobile apps that uses some user data, the data class:
class UserData{
public:
Address address;
bool isVerified=false;
};
class Address{
};
The UserData may be loaded from the server JSON, so I need rapidJson, and also write some methods to assign the data from rapidJson to the object.
Instead of using active record pattern that writes the json-to-object methods (eg:fromJson()) to the object itself, I create some parallel classes that resembles the structure of UserData:
class UserDataSerializer{
public:
static void fromJson(rapidJson::Value value,UserData& userData){
AddressSerializer::fromJson(value["address"],userData.address);
userData.isVerified=value["isVerified"].GetBool();
}
};
class AddressSerializer{
static void fromJson(rapidJson::Value value,Address& address){
}
};
So that only the pages that loads UserData depend on the UserDataSerializer class, while the other pages that accesses user data only depend on UserData class. When UserData adds a new object property, I also need a new serializer.
My question is, is it a code smell?
1