I am learning Mulesoft 4 and trying to run a filter on a list of books. In the Transform message, there are no errors and in the preview, the books are filtered by price as expected.
When I run the request in my REST client, I get the following 500 Server Error error. When I remove the filter, I get a successful post in REST. I set a breakpoint on the Transform component and got the error below. How can I fix this?
Detailed error description
INFO 2021-03-27 16:51:32,014 [[MuleRuntime].uber.05: [data-weave-1].data-weave-1Flow.CPU_LITE @6c4cd988] [processor: data-weave-1Flow/processors/0; event: 979d4040-8f46-11eb-8c87-6817296a6b20] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Start upload
ERROR 2021-03-27 16:54:05,959 [[MuleRuntime].uber.04: [data-weave-1].data-weave-1Flow.CPU_INTENSIVE @744a745c] [processor: ; event: 979d4040-8f46-11eb-8c87-6817296a6b20] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : "Types `Array` and `Number` can not be compared.
6| book: payload.catalog.*book filter($.price < 10) map ((data, index) ->
^^^^^^^
Trace:
at main (line: 6, column: 37)" evaluating expression: "%dw 2.0
output application/json
---
catalog:
{
book: payload.catalog.*book filter($.price < 10) map ((data, index) ->
{
autor: data.author,
title: data.title,
genre: data.genre,
price: data.price
})
}".
Element : data-weave-1Flow/processors/1 @ data-weave-1:data-weave-1.xml:15 (Transform Message)
Element DSL : <ee:transform doc:name="Transform Message" doc:id="f3e0bf40-cf5f-421b-a895-b75fbd5ff58e">
<ee:message>
<ee:set-payload>%dw 2.0
output application/json
---
catalog:
{
book: payload.catalog.*book filter($.price < 10) map ((data, index) ->
{
autor: data.author,
title: data.title,
genre: data.genre,
price: data.price
})
}</ee:set-payload>
</ee:message>
</ee:transform>
Error type : MULE:EXPRESSION
FlowStack : at data-weave-1Flow(data-weave-1Flow/processors/1 @ data-weave-1:data-weave-1.xml:15 (Transform Message))
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Input code
{
"catalog": {
"book": [
{
"autor": "Knorr, Stefan",
"title": "Creepy Crawlies",
"genre": "Horror",
"price": "4.95"
},
{
"autor": "Randall, Cynthia",
"title": "Lover Birds",
"genre": "Romance",
"price": "4.95"
},
{
"autor": "O'Brien, Tim",
"title": "MSXML3: A Comprehensive Guide",
"genre": "Computer",
"price": "36.95"
},
{
"autor": "Corets, Eva",
"title": "Maeve Ascendant",
"genre": "Fantasy",
"price": "5.95"
},
{
"autor": "O'Brien, Tim",
"title": "Microsoft .NET: The Programming Bible",
"genre": "Computer",
"price": "36.95"
},
{
"autor": "Ralls, Kim",
"title": "Midnight Rain",
"genre": "Fantasy",
"price": "5.95"
},
{
"autor": "Corets, Eva",
"title": "Oberon's Legacy",
"genre": "Fantasy",
"price": "5.95"
},
{
"autor": "Kress, Peter",
"title": "Paradox Lost",
"genre": "Science Fiction",
"price": "6.95"
},
{
"autor": "Thurman, Paula",
"title": "Splish Splash",
"genre": "Romance",
"price": "4.95"
},
{
"autor": "Corets, Eva",
"title": "The Sundered Grail",
"genre": "Fantasy",
"price": "5.95"
},
{
"autor": "Galos, Mike",
"title": "Visual Studio 7: A Comprehensive Guide",
"genre": "Computer",
"price": "49.95"
},
{
"autor": "Gambardella, Matthew",
"title": "XML Developer's Guide",
"genre": "Computer",
"price": "44.95"
}
]
}
}



$.priceis returning an array, or you're getting a data structure where$.pricereally is just an array. Even though preview is correct, preview uses metadata not the actual output. Slap a breakpoint on and debug, then use the evalulate dataweave window to just dopayload.catalog.*bookand see what the structure looks like. - Michael Jones