Import mapping flatening - map with parent - Mendix Forum

Import mapping flatening - map with parent

3

Quite often in XML and JSON messages, the attributes are broken down into many sub-elements.

To keep the domain model clean, we want to agregate many dispatched attributes to one single Mendix entity.

IT’s possible to address this use case by using a microflow on the element, but we have to assign the microflow on every attributes.

Microflows are still making sense for more elaborate use cases.

But here the case is quite simple, it would be much more intuitive and faster for the developer to have an option to map attributes to a parent object.

 

 

the solution today is to create a microflow on every elements, it receives the parent object and return it without doing anything

asked
2 answers

Hi Nicolas, to me it looks like you're trying to map an array into a single entity. From your screenshot, a single `item` in your JSON looks like can have multiple `choice`s, and in turn multiple `title`s and `description`s.


For 1-1 relationship, you can already flatten the object into a single entity. See the example below:

You want to map this JSON

{
    "product": "name",
    "description": "desc",
    "stock": {
        "price": 1.0,
        "quantity": 50
    }
}

into this entity:


You can configure the Import Mapping such that the structure is flattened by not checking the "intermediate object" (in this case, `stock`):


Everything will then be at root level and you can easily map it to an entity.



In cases where you know that your array always has one element, from Mendix 11.12 you can use the Data Transformer feature to transform your JSON, extracting that element and flattening it into a flat JSON before using it as a source for Import Mapping.

Created

Yes, please. Came across lots of use-cases for this.

Created