0

I'm using a data mapper which maps xml file to array of maps. While logging I get the result given below:

[{Name=xyz, Salary=30000, Tax=1000}, {Name=BOS, Salary=200, Tax=75}]

From the above resulting map I'm trying to insert value to the database based on where clause. My query looks something like this:

UPDATE employee SET Salary =#[message.payload[0]['Salary']]  WHERE name = #[message.payload[0]['Name']]

Here I'm getting exception which looks something like:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at org.mvel2.optimizers.impl.refl.nodes.ListAccessor.getValue(ListAccessor.java:40)
at org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:40)
at org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

While logging using #[message.payload[0]['Salary']] I get the value associated with it correctly. But the same expression in query doesn't work for me.

Waiting for your reply.

Thanks.

Balwant Kumar Singh
  • 1,158
  • 4
  • 24
  • 48

1 Answers1

1

Take the first item (or split the array) before using the query:

<set-payload value="#[payload[0]]" />

And then use just the map payload in the query:

#[message.payload['Salary']]
Anton Kupias
  • 3,945
  • 3
  • 16
  • 20
  • Well that's okay, but I'm still confused, why #[message.payload[0]['Salary']] doesn't work. In logger it's give me the correct value for the key "Salary". – Balwant Kumar Singh Apr 08 '14 at 09:35