3
votes

I have this json payload, I would want to collect all externalListingId in one shot -

{
"listings": {
    "numFound": 3,
    "listing": [
        {
            "status": "INACTIVE",
            "pricePerTicket": {
                "amount": 100,
                "currency": "USD",
            },
            "paymentType": "1",
            "externalListingId": "12208278",
            "city": "New York"
        },
        {   "status": "ACTIVE",
            "pricePerTicket": {
                "amount": 4444,
                "currency": "USD"
            },
            "paymentType": "1",
            "externalListingId": "CID1421798897102:151681733",
            "city": "Seattle"
        }
      ]
   }
}

I am using MVEL expression -

<enricher target="#[flowVars['sData']]" source="#[(externalListingId in payload.listing)]" doc:name="Message Enricher">
    <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
    </enricher>

But this is giving error !! - Message payload is of type: ReleasingInputStream.

Scenario - I would like to collect all externalListingId into flowVariable, convert to hashmap. I have another CSV file as input, would like to loop through that payload and check if this map contains the id!!

I am following this earlier post - Extracting array from JSON in mule esb

2

2 Answers

5
votes

You need to transform the message's streaming payload to an object with:

<json:json-to-object-transformer returnClass="java.lang.Object" />

before the enricher, and remove the one you have inside of it.

You also need to fix your MEL, as the listings property is missing in it:

source="#[(externalListingId in payload.listings.listing)]"

Source: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-JSONProcessing

0
votes

it worked with the same definition.

<flow name="test-mule-json-extractFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/json" doc:name="HTTP"/> <enricher source="#[(externalListingId in payload.listings.listing)]" target="#[flowVars.ids]" doc:name="Message Enricher"> <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/> </enricher> <logger message=":::::::::::::::#[flowVars.ids]" level="INFO" doc:name="Logger"/> </flow>

Note: the json input you mentioned is not valid due to available of an extra comma.