Hi Peter,
Could you also provide an updated screenshot of your domain model?
What I think goes wrong is that when using the REST services module, the main entity (in your case 'Order') should be the owner of the association, and the association should be a reference set (many to many). Please see this and the other examples from https://github.com/mendix/RestServices/. Specifically check the way the OrderLines association has been set-up between OrderView and OrderLineView.
When using 'OrderView' as main object, serializing this would result in the following JSON. Deserialization works exactly the same, in order to deserialize the JSON below to your domain model, your domain model should be set up as shown above.
{
"Nr": 1,
"Total": 9.4,
"OrderCustomer": "http://localhost:8080/rest/customers/3",
"OrderLines": [
{
"Description": "Coffee Biscuits 36pcs",
"Amount": 2,
"Price": 0.89
},
{
"Description": "Dark Coffee 36pads Limited Edition",
"Amount": 3,
"Price": 2.54
}
]
}
Hope this helps!
Hi Peter,
This is indeed possible, and the output is controlled by your domain model. You are very close in what you have. To have 'orderline' be an array included as part of the order in JSON, you will need to:
1) Have the association 'Entity_Order' re-named to 'orderline' as Mendix expects the associations, not the entity name' to drive the labeling of arrays
2) This association should be many-to-one as you have in your example
3) REST calls should be made with non-persistent entities
Hope this helps,
Rob
Thanks Rob and Allard
I changed the association like:
This works! Thanks for helping. I think it is a little bit strange. One order has n lines, you can't define this in your domainmodel. 'n orders has n lines' works and this is good enough.
Peter.