Export mapping from one Entity to Json with Sub-Entitys

0
I am new to Mendix and have the following problem with the export mapping to a JSON:   Users should be able to create articles in our app. This data is stored in an 'Article' entity. Now, in order to pass the articles to another program via API, I want to create an export mapping.   Here, I have the problem that for the mapping of the JSON's 'sub-entities', I cannot use the data from the 'Article entity' because it is already being used by the 'Root entity' of the JSON (see screenshot). If I assign the 'Article' entity again as a parameter, I get the error 'You should not use the option 'from parameter' more than once in a mapping' (which makes sense).   My question is whether it is possible at all to create an export mapping from one entity to a JSON with multiple sub-entities without creating a workflow where I manually create the mapping.   And if it is actually possible, how?
asked
1 answers
2

Hi Florian,

 

When dealing with export mappings/JSON structures for an API, it is usually best if this is contained in a separate module with a separate domain model (with non-persistent entities) matching the JSON structure. 

 

So, before sending the API call you have a microflow to convert your persistent/main objects into the non-persistent objects, then apply the export mapping on the non-persistent object.

 

Main reason is that the API structure can change over time, which might require changes in the persistent domain model, which leads to potential data migrations for structural changes. By adopting a separate model for the API, you only need to change your 'mapping microflow' and your persistent domain model is not affected by the API (and does not impose any limitations on the API)

 

As an alternative, I believe there is an option to return an object by microflow (open export mapping, select target object, method="By microflow".  This microflow can use the 'parent' object (in your case, Article) as an input parameter, and return that same object as an output parameter which circumvents the issue of reusing the same parameter twice.

 

Hope this helps!

 

Cheers, Joost

answered