48
Views
2
Comments
Copy complex structure (REST response) to structure (internal)
Question

We have a complex structure from our REST API response.
It is about 6 layers deep with multiple lists (about 50).
To promote independancy of the module and keep the structure private to the API, we like to copy the structure to it's own internal version. And share that internal version with the other modules.

Which brings me to my question.
What is the easiest way to copy the data from 1 structure (which contains many lists) to another structure?

The only way I found so far was to manually to 50 times the action AppendListAll.
This seems very labour intensive and error prone. Any other suggestions on how to copy data from 1 to the other?

Rank: #471

After experimenting a bit with JSONserialize and JSONdeserialize it seems that this is a good way to move data from 1 structure to another.

First serialise the structure to JSON data.
Then deserialize the JSON data back to the new structure.

Would you guys agree that this would be a good way to solve the problem? And so prevent having to do 50 ListAppendAll manual actions to move data from 1 to the other?

Rank: #139

Hi Paul,


what exactly is the problem you are solving with this ?  

It looks to me like you're planning on having an "internal" structure that is (almost) a 1-on-1 copy of the API response structure.  That doesn'l feel like you are really adding any independence this way, if any downstream consumer does something with attribute X in list Y, 3 levels deep, that code will still break if this attribute changes in the api.

Why do you look at the API output structure in your consuming module as part of the API, it is really part of your module, it is your modules interpretation of the API response and you can do with it as you see fit.

In fact, OS is already doing what you are trying to do, it deserialises the API JSON into your structure.


That being said, in a more general context, yes you can serialise out of one structure and into another to copy all data that have matching JSON names.

Dorine