symfony2 Jsonresponse

if you wanna to encode a json object as the json response, you must set all the property of this objec in public, or it will not work. Like this:
class JsonResponseData{
 public $msg;
 public $data;
 public $errMsg;
 public function setMsg($msg){
 public function get(){
  return $this->msg;
 public function setData($data){
 public function getData(){
  return $this->data;
 public function setErrMsg($errMsg){
 public function getErrMsg(){
  return $this->errMsg;
before i set them in private, and i always get a void response object. after i set them to public ,everything works fine.