title: How to pass Java object to a Java function in mule
body: <p><a href="https://i.stack.imgur.com/HaTCH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaTCH.png" alt="enter image description here"></a></p>
  
  <p>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 <strong>req</strong>.
  The method validate accepts a Java Object Of type Example</p>
  
  <pre><code>public HashMap&lt;String, String&gt; validate(Example req) {.......}
  </code></pre>
  
  <p>Example class looks like this:</p>
  
  <pre><code>Class Example{
  String key1;
  String key2;
  String key3;
  }
  </code></pre>
  
  <p>XML configuration looks like this :</p>
  
  <pre><code>&lt;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"&gt;
                  &lt;java:args &gt;&lt;![CDATA[#[{key1 :payload.key1,key2: payload.key2, key3:payload.key3}]]]&gt;&lt;/java:args&gt;
              &lt;/java:new&gt;
              &lt;java:invoke doc:name="Invoke" doc:id="dd5f6534-06c8-4f4d-b3aa-c634a629898e" class="Implementations.ValidationServiceImpl" instance="#[vars.validator]" method="validate(Entities.Example)"&gt;
          &lt;java:args &gt;&lt;![CDATA[#[vars.req]]]&gt;&lt;/java:args&gt;
      &lt;/java:invoke&gt;
  </code></pre>
  
  <p>I get the following error:
  <a href="https://i.stack.imgur.com/fHk4Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fHk4Z.png" alt="enter image description here"></a></p>
  
  <p>I don't know why is it not passing the java object as a whole.</p>