I send data to and from my server.
I create a message, set the type (enum) and the objects that need to be transferred.
The message is sent as a compressed JSON string. When I receive it I parse the message, instantiate the object and start to fill it. When I need to instantiate the data transferred I use a map that contains the name of the class as a key and a pointer to the constructor as the value.
All this works fine but now I need to consume the message and do what needs to be done with it (send an answer, write to the DB, etc). What is the best way to do that ? For now, I check the type of the message and get each of the transferred object. But I don't know what class they are (not explicitly).
Should I dynamic cast everything (cost a lot for not much) ? Should I treat the data with the hope it will always be in the same order. Or should I store the objects as a map (with the name or a enum as the key) and cast it correctly then ?
I know that dynamic casting should not be done if possible. But here I am wondering, is it worth it to have a switch from the beginning and create the correct object and feed it the JSON ? For now the entire message is reconstructed dynamically without any problem and my message manager will handle the treatment, should I change that ?