mulemule-esbmel

How properly convert ArrayList to String in MEL


so I have payload and part of it have array like such:

{
...
members [
  John,
  Robert,
  Tony
]
...
}

I try to set variable as:

#[payload.members joinBy(",")]

but its return it type as java.lang.ArrayList

however if doing same with DW 1.0 (output to variable):

%dw 1.0
%output application/java
---
payload.members joinBy ","

I receive it as needed type - java.lang.String

Any advice why it so or what I am doing wrong to get in MEL same as in transform component? (I am traying avoid using transform component for such simple step)


Solution

  • You are confusing two different languages. Mule 3.x uses MEL as its expression language. That means that every expression of the form #[...] is a MEL expression. Mule 3.7+ also supports DataWeave 1 inside the Transform component. Those are two different languages. The joinBy operation is a DataWeave operation so it is not expected to work in a MEL expression. I'm not sure why it is not just throwing an error.

    In MEL you could do something like this:

    #[ org.apache.commons.lang.StringUtils.join(payload.members, ",") ]
    

    Most basic Java expressions are compatible with MEL.

    Note that in Mule 4 the only expression language is DataWeave 2. There expressions work the same inside #[...] than in the Transform component.