object-mapper
object-mapper copied to clipboard
MapFrom does not support old keys
First: let me thank you for this awesome package. Been a user of the original EventSaucePHP/ObjectHydrator
from day 1. My main usage is parsing packages from different Websocket-based protocols. The one thing I noticed that's missing for me, and where I cannot seem to find a solution, is: if a field gets renamed in an upcoming version of a protocol, and I want to support both for the interim time, I cannot see how to do this: so basically: #[MapFrom("key-name", "key_name")]
where key-name
is the new syntax of the key, but I also want to support the old key_name
for some time to gently transition protocols.
I cannot find a solution to the problem, and the whole MapFrom-thing is baked deep into the code with no way to hook into it. So what I'm basically looking for is a way to have aliases for source keys, and a configurable way to say into which to serialize (the new or the old form). Am I too blind to see how this could be done? It would really make supporting multiple versions of a protocol, or also multiple layouts of configuration files, a lot easier. Well … actually, it would make it possible, because right now, I don't't see how I could do it without a completely separate renaming process in front end behind.