daniel_mutu
daniel_mutu

Reputation: 163

Mule 4, get uri params with Anypoint application

I'm new in Mulesoft, I'm following Quickstart guide. In Step 2 (https://developer.mulesoft.com/guides/quick-start/developing-your-first-mule-application), I need to receive variables from URI in this way:

[{'id' : attributes.uriParams.productId}]

But when I try my GET I have the following error in console:

**Message : "Cannot coerce Array ([{id: "2" as String {class: "java.lang.String"}}]) to Object 1| [{'id' : attributes.uriParams.productId}] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trace: at main (line: 1, column: 1)" evaluating expression: "[{'id' : attributes.uriParams.productId}]". Error type : MULE:EXPRESSION Element : get:\products(productId):test_daniel-config/processors/1 @ test6_db_connection:test_daniel.xml:133 (Select) Element XML : SELECT product.,CONCAT('["', (GROUP_CONCAT(variant.picture SEPARATOR '","')),'"]') AS pictures,CONCAT('[', GROUP_CONCAT('{"',variant.identifierType, '":"', variant.identifier, '"}'),']') AS identifiersFROM product INNER JOIN variant ON product.uuid = variant.productUUIDWHERE product.uuid = :id; #[[{'id' : attributes.uriParams.productId}]] *

Any Ideas? Thanks!

Upvotes: 0

Views: 2670

Answers (1)

satish chennupati
satish chennupati

Reputation: 2650

cannot coerce Array to object error pop's up when you are using an array where you were supposed to use an object.

in the exception above the uri-param should be treated as ab object i.e. enclosed in {} but its being treated as an array of objects [{}].

this is causing the error.

Upvotes: 1

Related Questions