I’m having this issue with JMSSerializerBundle. It basically gives me an exception for something that I’ve already done. This is my entity:
Edited to avoid confusion about annotation lines
<?php
namespace My\ProjectBundle\Entity;
use JMS\SerializerBundle\Annotation\Type;
use Doctrine\ORM\Mapping as ORM;
/**
* My\ProjectBundle\Entity\Music
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="My\ProjectBundle\Entity\MusicRepository")
*/
class Music extends Post
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $album
*
* @ORM\Column(name="album", type="string")
* @Type("string")
*/
protected $album;
/**
* @var string $artist
*
* @ORM\Column(name="artist", type="string")
* @Type("string")
*/
protected $artist;
/**
* @var integer $duration
*
* @ORM\Column(name="duration", type="bigint")
* @Type("int")
*/
protected $duration;
/**
* @var string $title
*
* @ORM\Column(name="title", type="string")
* @Type("string")
*/
protected $title;
/**
* @var array $genres
*
* @ORM\Column(name="genres", type="array")
* @Type("array")
*/
protected $genres;
As you can see, I’ve added @Type() annotations for the fields, but it still gives me the exception when I call:
$listenedMusic = $serializer->deserialize($content, 'My\ProjectBundle\Entity\Music', 'json');
I’ve checked and the $content variable is not empty and has all the fields mapped in JSON format.
In my Monolog files, this is the exact Exception:
[2012-11-29 23:39:07] request.CRITICAL: JMS\SerializerBundle\Exception\RuntimeException:
You must define a type for My\ProjectBundle\Entity\Music::$album. (uncaught exception)
at /vendor/jms/serializer-bundle/JMS/SerializerBundle/Serializer/GenericDeserializationVisitor.php line 177
Why does it still give me this exception?
I have fixed this by updating my entire project to
dev-masterpackages. It seemed it was a bug in JMSSerializer, because without modifying any code, I stopped getting this error.