Rest Services - Receiving the Body from a POST to my Mendix application

0
Hello Developers, I'm using the Rest services module from the AppStore with many useful functions. I am currently looking for the right Java call that will extract the Body (JSON) of a POST request sent to my application. The device will send me an "updateStatus" call with a JSON attached to the body. I can currently receive the POST but I can't find the right Java code for extraction from the body..  Because of the JSON size throwing it through the header (GetHeader java action) is not a valid (or decent) construction. I've been looking around for a while now and I've decided to ask this question on the forum. My current alternative would be to write the java code myself.  EDIT #1 - Partial Solution found:  The Rest Service manages to map the incoming JSON body (first depth) automatically to an entity with the same attribute names. Which is good, problem is now that it's only 1 depth. I can't figure out the second (or third) depth and how this can be mapped automatically to an associated entity and its attributes.  Edit #2 - See my last post for the solution that has worked for me :) !
asked
4 answers
2

Hello everyone, 

I have found the solution to my problem. I might not have explained it well. Up till today I can't exactly use the body as parameter or extract it using a java call. The Rest Service from the app store maps the attributes perfectly to a non-persistable entity (See post from Mike Kumpf). 

My second problem was to get the JSON depths mapped correctly as well, so I can use the data for validation and saving them into a persistable entity. After some testing this is what I've come up with and it works perfectly (see img).

See the JSON post in the body (postman) and the entity's I've created to map it on. In the microflow itself I have the parameter 'Entity' as object and because of the association 'car' it will also map the second entity (wwaa) perfectly because the association has the same name as the list object 'car'. 
Rest JSON solution (Automatic mapping)


I'd like to thank everyone for helping and thinking with me! This is the solution for me :)
Gr. Jermaine 

answered
1

Hi Jermaine,

  Have you tried the Java action deserializeObjectToJSON that is included in the REST module?  It sounds like that is what you might be looking for.

 

answered
1

Jermaine,

I got curious about this and, looking around at blog posts and Github, found this in the documentation - and thought it might help you out:

The blog post mentioned in this documentation can be reached here:  https://www.mendix.com/blog/rest-part-ii-publishing-microflows-rest/  and contains the following domain model with an entity that would be populated with information sent with the request - including JSON elements:

Hopefully some of this information will help you get pointed to a solution that works for you.

Mike

 

answered
0

You also have another alternative which is make use of the REST functionality within the Mendix platform. Its very easy to extract the body of the response > see response handling in the Call Rest action (import maping/store in string etc.). 

answered