You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class that needs to be serialized to an array. If I provide a serialization handler that returns an array, the returned serialized object is null
Example code:
use JMS\Serializer\Annotation\HandlerCallback;
class Container {
private $things = array();
public function addThing($thing) {
$this->things[] = $thing;
return $this;
}
public function getThings() {
return $this->things;
}
/**
* @HandlerCallback("json", direction = "serialization")
*/
public function serializeToJson() {
return $this->things;
}
}
If I try to
$container = new Container();
$container->addThing('something'); // optional
print_r($serializer->serialize($container, 'json'));
I get a null result. It doesn't matter if the array is empty or not, if it is associative or not.
The text was updated successfully, but these errors were encountered:
I have a class that needs to be serialized to an
array
. If I provide a serialization handler that returns an array, the returned serialized object isnull
Example code:
If I try to
I get a
null
result. It doesn't matter if the array is empty or not, if it is associative or not.The text was updated successfully, but these errors were encountered: