douping7975 2014-04-10 16:57
浏览 33

在Symfony中使用JSON反序列化实体失败

I'm trying to deserialize an entity from a JSON file with this method

public function importAnnotationAction($id_rendu)
{
    $em = $this->getDoctrine()->getEntityManager();

    $jsonContent = $this->get("request")->getContent();

    $serializer = $this->get('serializer');
    $annotationEntity = $serializer->deserialize($jsonContent, 'Alecsia\AnnotationBundle\Entity\Annotation', 'json');

    //Save entity
    $em->persist($annotationEntity);
    $em->flush();

    return new Response($jsonContent . "
" . var_dump($annotationEntity));
}

the JSON file used is from a same entity

and the output entity fields are all set to null :

object(Alecsia\AnnotationBundle\Entity\Annotation)#568 (18) { ["id":protected]=> int(26) ["fichier":protected]=> NULL ["rendu":protected]=> NULL ["modele":protected]=> NULL ["debut_ligne":protected]=> int(0) ["debut_col":protected]=> int(0) ["fin_ligne":protected]=> int(0) ["fin_col":protected]=> int(0) ["nom":protected]=> NULL ["commentaire":protected]=> NULL ["valeur":protected]=> NULL ["relatif":protected]=> NULL ["exercice":protected]=> NULL ["deleguer_nom":protected]=> bool(false) ["deleguer_commentaire":protected]=> bool(false) ["deleguer_valeur":protected]=> bool(false) ["deleguer_relatif":protected]=> bool(false) ["deleguer_exercice":protected]=> bool(false) }

and the entity id increment with each call, what am I doind wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器