php - Serializing and Deserializing in Symfony -


i serializing entities symfony bundle "symfony/serializer".

i able encode entity json no problems, having problems deserializing , bringing original form. error receiving is;

could not denormalize object of type appbundle:entity, no supporting normalizer found. 

defaultcontroller.php

    //create entity serialize     $entity = new entity();     $entity->setid(1);     $entity->setname('john');      //create serializer serialize entity     $encoders = array(new xmlencoder(), new jsonencoder());     $normalizers = array(new objectnormalizer());     $serializer = new serializer($normalizers, $encoders);     $jsoncontent = $serializer->serialize($entity, 'json');      var_dump($jsoncontent); // returns string '{"id":1,"name":"john"}' (length=22)  << good!       //deserialize entity     $person = $serializer->deserialize($jsoncontent, 'appbundle:entity', 'json');     //<error here>//      var_dump($person);  

entity.php

namespace appbundle\entity;  class entity {  private $id;  private $name;  public function getid() {     return $this->id; }  public function setid($id) {     $this->id = $id; }  public function getname() {     return $this->name; }  public function setname($name) {     $this->name = $name; }  } 

not sure missing, appreciated.

deserialize() should namespace of entity need change appbundle:entity appbundle\entity.

$person = $serializer->deserialize($jsoncontent, 'appbundle\entity', 'json'); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -