Search code examples
mulemule-studiomulesoftmule-esb

How to call a java method with Long type in Mule4?


My Java class has a constructor like

public Authenticator(String username, String applicationId, String zz, String yy, String zz,
            String vv,Long cc) {
        ..
    }

Im initiating this constructor in mule as follows;

    <java:new doc:name="Authenticator" doc:id="b63fe250"
            class="org.xxx" constructor="Authenticator(String,String,String,String,String,String,Long)"
            target="authenticator">
            <java:args ><![CDATA[#[output application/java
---
{
arg0 : p('zz') , 
arg1:vars.'vv', 
arg2:'xx', 
arg3:'aa',
arg4:vars.'zz',
arg5:'zz',
arg6:vars.nonce as Long
}]]]></java:args>
        </java:new>

Here Im getting; Unable to resolve reference of Long. at 10 : 10" evaluating expression: "output application/java

How can I define the variable nonce as Long in mule?


Solution

  • Dataweave does not operate with primitive types. It works with classes. Then it tries to convert them to primitive types using data sense. Try to use Number but with class Long. It should look like this:

    {
    arg0 : p('zz') , 
    arg1:vars.'vv', 
    arg2:'xx', 
    arg3:'aa',
    arg4:vars.'zz',
    arg5:'zz',
    arg6:vars.nonce  as Number {class: "java.lang.Long"}
    }
    

    Look for more examples here https://simpleflatservice.com/mule4/ValuesAsJavaLong.html