I have a a requirement to expose a REST web service in Mue .. My Mule flow is as follow :-
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainData"/>
</jersey:resources>
</flow>
Now my question is if I post a JSON request to this REST service .. How can I map the request which is in a Sting format into a object mapped with input parameters of MainData class .. for example .. If I post the following JSON request from a REST client as a request body :-
{
"insertDataRequest": [
{
"id": "288",
"name": "Sidray",
"age": "55",
"designation": "SE"
}
]
}
The request gets into the flow as a String .. Now in Java class MainData, I can use GSON parser to parse the String .. but here I don't want to use GSON in Java class MainData to parse the String request and get id, name, age values .. instead of that I want a Mule transformer or something like that to parse the String and map into an Object before the java class so that in MainData class I can map with the input as following :-
public class MainData
{
@Override
@POST
@Produces("application/json")
@Path("/insert/")
public DataResponse insertDataOperation(int id,String name,int age,String designation)
{
// Here all the values like are mapped with input parameter
}
}
Is there any way in mule to convert the input request String into an Object and map with input parameter ?? Is this the right approach to expose a REST webservice which intake a JSON request .. please suggest ??