1

enter image description here

I am trying to invoke a java function in mule.I converted the payload into the Object and passed it in the function. The name of the Java object created is req. The method validate accepts a Java Object Of type Example

public HashMap<String, String> validate(Example req) {.......}

Example class looks like this:

Class Example{
String key1;
String key2;
String key3;
}

XML configuration looks like this :

<java:new constructor="Example(java.lang.String,java.lang.String,java.lang.String)" doc:name="New Example" doc:id="6a1d5c8c-a1f0-446e-ab49-99a21fbbf4b9" class="Entities.Example" target="req">
                <java:args ><![CDATA[#[{key1 :payload.key1,key2: payload.key2, key3:payload.key3}]]]></java:args>
            </java:new>
            <java:invoke doc:name="Invoke" doc:id="dd5f6534-06c8-4f4d-b3aa-c634a629898e" class="Implementations.ValidationServiceImpl" instance="#[vars.validator]" method="validate(Entities.Example)">
        <java:args ><![CDATA[#[vars.req]]]></java:args>
    </java:invoke>

I get the following error: enter image description here

I don't know why is it not passing the java object as a whole.

HMT
  • 2,093
  • 1
  • 19
  • 51
  • Please post the complete flow and the definition of the constructor for the ValidationServiceImpl class in the flow since your flow missing " – Alan M Jan 02 '20 at 08:39
  • @AlanM I have updated the same – HMT Jan 02 '20 at 09:12

1 Answers1

5

Please try with this and see. If it works for you please let me know. We need to improve the mule documentation in this case

<java:args >#[{req: vars.req}]</java:args>
Alan M
  • 616
  • 5
  • 15
  • 1
    Great to hear that. I have informed the mule documetation team to update the documentation to reflect additional case where the object is a java custom class instantiated from the workflow – Alan M Jan 02 '20 at 12:09
  • Hi Alan , please help me with this question as well https://stackoverflow.com/questions/61095074/how-to-convert-managedcursorstreamprovider-to-json-object-in-mule-4 . Thanks in advance – HMT Apr 08 '20 at 09:20