Data Mapping between structure

Hi community!

I've got a design concern for you. Everything works but, the implementation is not "pretty" and I'm sure something better can be done.

Here is the case: I've got two structures and a server action which transform data from one structure to another. A map function.

My problem is, later on, I will have to do this kind of mapping for a lot of conversion. As you can see on the screenshot, I've got a switch doing the routing to the good map (in the example, map n1 is "TitleCanonicalTo.." and n2 has no conversion), but how to make it more "scalable" if I've 50 mappings to do later?

I was thinking about a data based mapping but I'm not too sure if that's the good approach.

Thanks for your thoughts :-)

PS : Mapping works like this : A string as in parameter, deserialize in source structure, map to target structure, serialize. return the new string.


Not in OS, but I once had a similar situation. Two major flows, each with around 20 different maps.

Visually it was a nightmare, but I managed to reduce it to a two-way switch and do a data-based mapping, only deciding if it was flow 1 or flow 2 (different systems).

In the end, it was a bit worse for performance, but because I was sure of the volume of data, and the frequency of changes, simplifying the developer's life was more important than processing speed.

We learn that we should always prioritize performance, but this was the only exception I ever made, and don't regret it at all.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.