0

I have a mule flow like this --

<flow name="mule_dbFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <db:select config-ref="Oracle_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[SELECT sf.MAESTRO_ID, sf.SFTP_HOST, fm.SOURCE_TYPE, fm.ENCRYPTION, fm.SOURCE_MAESTRO_ID, fm.TARGET_MAESTRO_ID from sftp_mule sf,  filemover_location_tbl 			fm where sf.maestro_id = fm.SOURCE_MAESTRO_ID]]></db:parameterized-query>
        </db:select>
        
        <json:object-to-json-transformer doc:name="Object to JSON"/> 
        <logger level="INFO" doc:name="Logger" message="Data: #[payload]"/>

        <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.HashMap"/>
        <logger level="INFO" doc:name="Logger" message="NEW DATA**** #[payload.SOURCE_TYPE]"/>
        
	   <choice doc:name="Choice">
                    <when expression="#[(payload.SOURCE_TYPE == 'file') || (payload.SOURCE_TYPE == 'sftp')]">
                         <json:object-to-json-transformer doc:name="Object to JSON"/>
                		<logger level="INFO" doc:name="Logger" message=“SFTP Data: #[payload]"/>
                    </when>
                    <otherwise>
                        <logger message="Default Choice" level="INFO" doc:name="Logger"/>
                    </otherwise>
         </choice>
    </flow>

After the object-to-json-transformer the json looks like this.

[{"SOURCE_MAESTRO_ID":"LIPSTP01_FTUPN","SOURCE_TYPE":"sftp","SFTP_HOST":"sftp.intersourcing.com","TARGET_MAESTRO_ID":"LIPSTP01_PS","MAESTRO_ID":"LIPSTP01_FTUPN","ENCRYPTION":"no"}]

But after that when i try to transform the json to a HashMap it throws error --

Failed to transform from "json" to "java.util.HashMap". Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException). Message payload is of type: String

But if i change it to java.util.List there is no error. But in that case I am not able to perform the choice.

What am i doing wrong ?

1 Answer 1

4

Your SQL query will return a List of Maps. So make sure you configure the transformer to return an array of maps.

<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.HashMap[]"/>
1
  • 1
    I like to just use java.util.List here, but the array works too. Your choice expression implies that you're only interested in one record. You could update it to refer to the first element of the array like so: "payload[0].SOURCE_TYPE == 'file'". It might be a little more intuitive to transform the payload to a single map after the json-to-object-transformer with <set-payload value="#[payload[0]]" /> and keep your choice expressions the way they are.
    – Ryan Hoegg
    Oct 31, 2015 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.