Hi David,
If you want to have the structure even when no items are present you could resort to a non persistent domain model for the purpose of creating the desired structure. This normally looks alot like your persisent domain model but gives you the freedom to design the response in the way you want. But beware, a lot of extra work because of need of custom mapping microflows from persistent to non persistent.
In your case I would add an attribute in the root object that contains the value/amount of the array of products. This way your consumers can read the value and then know if the need to process further or not. An example:
{
..."Key":2,
..."Name":"Product range",
...”NoOfProducts”: 0
}
{
..."Key":2,
..."Name":"Product range",
...”NoOfProducts”: 2,
..."Products":[
......{
........."Key":30,
........."UKitem":"EOS_002834"
......},
......{
........."Key":33,
........."UKitem":"EOS_009277"
......}
...]
}
Hi Sjors,
Thanks for the reply. The addition of a field with the No. of Products is indeed a possible way to inform the receiving system that no list is to be expected. However I'm curious about your first option regarding the non persistent domain model. This is because I already have made non-persistent entities that essentially define the structure of my message. Using the message definition feature in Mendix I select these non-persistent entities which Mendix subsequently uses as a template for my JSON message structure. In the export mapping I select this message definition which then requires me to specify the entities with attributes that are used to fill out the fields of my message. All this is indeed a bit more cumbersome, but still doesn't allow me to always show the list in my message structure since the ‘list’ is a representation of the 0..1-association between the child entity(s) and the parent entity. Therefore no child(s) objects means no associations are defined hence no list in the response message is created. How should this still be possible according to your best knowledge using non-persistent entities when there are no child objects?