Reputation: 573
I have a JSON response which is like {"id":10,"name":"ABCD","deptId":0,"address":null}
I need to split this JSON and extract the id to pass on to another service. My mule xml is as below
<jersey:resources doc:name="REST">
<component class="com.employee.service.EmployeeService"/>
</jersey:resources>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="Employee Response #[payload]" level="INFO" doc:name="Logger"/>
<set-payload value="#[payload]" doc:name="Set Payload" />
<json:object-to-json-transformer doc:name="Convert String to JSON" />
<logger message="JSON Response #[payload]" level="INFO" doc:name="Logger"/>
<json:json-to-object-transformer returnClass="java.util.Map" />
<expression-transformer expression="#[payload]" />
<collection-splitter />
When I run this I get the error
Object "java.util.LinkedHashMap" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException). Message payload is of type: LinkedHashMap
How can I fix this error?
Thanks
Upvotes: 0
Views: 995
Reputation: 4704
The JSon module as well has the ability to use jsonpath in expressions, such as:
#[json:/id]
Upvotes: 0
Reputation: 475
I believe the error you are getting is already on this part, <collection-splitter />
. Have you debugged this already?
Not sure what the splitter is for but you can simply do #[payload.id]
to get id once you have a HashMap type of payload.
Upvotes: 0
Reputation: 207
remove your last four lines of code. set logger #[payload.id] in flowvars and access it
Upvotes: 0