title: Controller dispatch error in Zend framework 2
body: <p>I am returning Json response from zend controller. </p>
  
  <p>This is my code</p>
  
  <p><strong>Controller Code</strong></p>
  
  <pre><code>public function get()
  {
  
      $result = //calling other function and getting response in array
  
      print("value in controller before calling toJsonModel");
      print_r($result);
      $temp = $this-&gt;toJsonModel($result);
      var_dump($temp);
  
      return $temp;
  }
  </code></pre>
  
  <p><strong>toJsonModel</strong> function</p>
  
  <pre><code>public function toJsonModel($data = array())
  {   
      $data['requestId'] = $this-&gt;getHeader('RequestId');
      print("Value just before returning to controller");
      print_r($data);
      return new JsonModel($data);
  }
  </code></pre>
  
  <p><strong>Response</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Wo62j.png" alt="enter image description here"></p>
  
  <p>First and second print displays correct values. But after getting values from toJsonModel when I try to displays wrong values and adds some other values like "captureTo", "terminate" and "children" as protected.</p>
  
  <p>I don't know why it's giving me wrong message. </p>
  
  <p>Can any one guide me to right path and tell me what the problem is ?</p>
  
  <p>Thanks in advance. </p>
  
  <p><strong>EDIT</strong>
  I am adding new screenshot to display full message.</p>
  
  <p><strong>ERROR</strong> : </p>
  
  <blockquote>
    <p>{"name":"Email Not Found","message":"No account found with this email
    address.","code":404,"requestId":"12","reason":"error-controller-cannot-dispatch","display_exceptions":true,"controller":"RSMobile\Controller\ForgotPassword","controller_class":null}</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/Wk9Xp.png" alt="enter image description here"></p>