0
votes

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

4

4 Answers

0
votes

I was able to get this done by writing a custom converter

0
votes

remove your last four lines of code. set logger #[payload.id] in flowvars and access it

0
votes

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.

0
votes

The JSon module as well has the ability to use jsonpath in expressions, such as:

#[json:/id]