JMSSerializer Bundle does not serialize relationships

0

Controller:

public function newUserAction(Request $request)
{
    $errores = array();
    $usuario = new Usuario();

    $foto = $request->files->get('foto');
    $email = $request->request->get('email');
    $username = $request->request->get('username');
    $pass = $request->request->get('password');

    if ($email == null){
        array_push($errores, 'El Email no puede estar vacío') ;
    }
    if ($pass == null){
        array_push($errores, 'El Password no puede estar vacío') ;
    }
    $helper = $this->get('my_service.helper');

    if (count($errores) == 0){
        $fecha_ahora = new \DateTime("now");

        $usuario->setEmail($email);
        $usuario->setUsername($username);
        $em = $this->getDoctrine()->getManager();
        $perfil = $em->getRepository('MainBundle:Perfiles')->find(1);
        $usuario->setPerfil($perfil);

        $factory = $this->get('security.encoder_factory');
        $encoder = $factory->getEncoder($usuario);
        $salt = $helper->randomString(25,true,true,true);
        $usuario->setSalt($salt);
        $password = $encoder->encodePassword($pass, $salt);
        $usuario->setPassword($password);

        $confirmationToken = $helper->randomString(30,true,true,true);
        $usuario->setConfirmationToken($confirmationToken);
        $usuario->setFechaRegistro($fecha_ahora);
        $usuario->setFechaUltimoLogin($fecha_ahora);

        if ($foto!= null){
            $helper->guardaFotoUsuario($foto);
        }
        $em = $this->getDoctrine()->getManager();
        $em->persist($usuario);
        $em->flush();
    }

    $usuarioPresenter = $helper->getUsuarioPresenter($usuario);
    if (count($errores) > 0){
        foreach ($errores as $error){
            $usuarioPresenter->addError($error);
        }            
    }
    return $usuarioPresenter;

}

User entities and profiles:

<?php

namespace ...\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Type;

 /**
 * @ORM\Entity
 * @ORM\Table(name="usuario")
 * 
 */
class Usuario {

    /**
     * @var int
     * 
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     **/
    private $id;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=false)
     */
    private $email;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=true)
     */
    private $username;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=false)
     */
    private $password;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=true)
     */
    private $salt;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=true)
     */
    private $confirmationToken;

    /**
     * @var boolean
     * 
     * @ORM\Column(type="boolean",nullable=false)
     */
    private $activo = false;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=true)
     */
    private $sessionId;

    /**
     * @var string
     * 
     * @ORM\Column(type="string",nullable=true, length=20)
     */
    private $cifDni;

    /**
     * @var string
     *
     * @ORM\Column(type="string",nullable=true, length=14)
    */
    private $tlf;

    /**
     * @Type("array")
     * @ORM\Column(name="fechaRegistro", type="datetime",nullable=true)
    **/
    private $fechaRegistro;

    /**
     * @Type("array")
     * @ORM\Column(name="fechaUltimoLogin", type="datetime",nullable=true)
    **/
    private $fechaUltimoLogin;

    //relacion entre el usuario y su perfil
    /**
     * @Type("array")
     * @ORM\ManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
     * @ORM\JoinColumn(name="perfil", referencedColumnName="id")
     */
    private $perfil;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return Usuario
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set username
     *
     * @param string $username
     *
     * @return Usuario
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get username
     *
     * @return string
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     *
     * @return Usuario
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get password
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set salt
     *
     * @param string $salt
     *
     * @return Usuario
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;

        return $this;
    }

    /**
     * Get salt
     *
     * @return string
     */
    public function getSalt()
    {
        return $this->salt;
    }

    /**
     * Set confirmationToken
     *
     * @param string $confirmationToken
     *
     * @return Usuario
     */
    public function setConfirmationToken($confirmationToken)
    {
        $this->confirmationToken = $confirmationToken;

        return $this;
    }

    /**
     * Get confirmationToken
     *
     * @return string
     */
    public function getConfirmationToken()
    {
        return $this->confirmationToken;
    }

    /**
     * Set activo
     *
     * @param boolean $activo
     *
     * @return Usuario
     */
    public function setActivo($activo)
    {
        $this->activo = $activo;

        return $this;
    }

    /**
     * Get activo
     *
     * @return boolean
     */
    public function getActivo()
    {
        return $this->activo;
    }

    /**
     * Set sessionId
     *
     * @param string $sessionId
     *
     * @return Usuario
     */
    public function setSessionId($sessionId)
    {
        $this->sessionId = $sessionId;

        return $this;
    }

    /**
     * Get sessionId
     *
     * @return string
     */
    public function getSessionId()
    {
        return $this->sessionId;
    }

    /**
     * Set cifDni
     *
     * @param string $cifDni
     *
     * @return Usuario
     */
    public function setCifDni($cifDni)
    {
        $this->cifDni = $cifDni;

        return $this;
    }

    /**
     * Get cifDni
     *
     * @return string
     */
    public function getCifDni()
    {
        return $this->cifDni;
    }

    /**
     * Set tlf
     *
     * @param string $tlf
     *
     * @return Usuario
     */
    public function setTlf($tlf)
    {
        $this->tlf = $tlf;

        return $this;
    }

    /**
     * Get tlf
     *
     * @return string
     */
    public function getTlf()
    {
        return $this->tlf;
    }

    /**
     * Set fechaRegistro
     *
     * @param \DateTime $fechaRegistro
     *
     * @return Usuario
     */
    public function setFechaRegistro($fechaRegistro)
    {
        $this->fechaRegistro = $fechaRegistro;

        return $this;
    }

    /**
     * Get fechaRegistro
     *
     * @return \DateTime
     */
    public function getFechaRegistro()
    {
        return $this->fechaRegistro;
    }

    /**
     * Set fechaUltimoLogin
     *
     * @param \DateTime $fechaUltimoLogin
     *
     * @return Usuario
     */
    public function setFechaUltimoLogin($fechaUltimoLogin)
    {
        $this->fechaUltimoLogin = $fechaUltimoLogin;

        return $this;
    }

    /**
     * Get fechaUltimoLogin
     *
     * @return \DateTime
     */
    public function getFechaUltimoLogin()
    {
        return $this->fechaUltimoLogin;
    }


    /**
     * Set perfil
     *
     * @param \TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil
     *
     * @return Usuario
     */
    public function setPerfil(\TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil = null)
    {
        $this->perfil = $perfil;

        return $this;
    }

    /**
     * Get perfil
     *
     * @return \TaurusUrsusApiRest\MainBundle\Entity\Perfiles
     */
    public function getPerfil()
    {
        return $this->perfil;
    }
}


<?php

namespace ...\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Perfil
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Perfiles
{

    /**
    * @var int
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    **/
    protected $id;

    /**
    * @var string
    *
    * @ORM\Column(name="nombrePerfil", type="string", length=250)
    **/
    protected $nombrePerfil;

    /**
     * @ORM\OneToMany(targetEntity="Usuario", mappedBy="perfil")
     */
    protected $usuarios;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->usuarios = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nombrePerfil
     *
     * @param string $nombrePerfil
     *
     * @return Perfiles
     */
    public function setNombrePerfil($nombrePerfil)
    {
        $this->nombrePerfil = $nombrePerfil;

        return $this;
    }

    /**
     * Get nombrePerfil
     *
     * @return string
     */
    public function getNombrePerfil()
    {
        return $this->nombrePerfil;
    }

    /**
     * Add usuario
     *
     * @param \TaurusUrsusApiRest\MainBundle\Entity\Usuario $usuario
     *
     * @return Perfiles
     */
    public function addUsuario(\TaurusUrsusApiRest\MainBundle\Entity\Usuario $usuario)
    {
        $this->usuarios[] = $usuario;

        return $this;
    }

    /**
     * Remove usuario
     *
     * @param \TaurusUrsusApiRest\MainBundle\Entity\Usuario $usuario
     */
    public function removeUsuario(\TaurusUrsusApiRest\MainBundle\Entity\Usuario $usuario)
    {
        $this->usuarios->removeElement($usuario);
    }

    /**
     * Get usuarios
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getUsuarios()
    {
        return $this->usuarios;
    }
}

JSON Resume:

{
    "entity": {
        "email": "[email protected]",
        "username": "Usuario desde postman",
        "password": "$2y$13$ZEE1QUB2JGEjcXMzOVcpe.0jx06mmqOQxUzj8f1OxtYhTxmkmHEU.",
        "salt": "dA5A@v$a#qs39W)xzrBLF($oA",
        "confirmation_token": "*Ud0OWeP5_M7;PUXD&(Rpwtcsz3|J&",
        "activo": false,
        "fecha_registro": {
            "date": "2018-01-12 09:57:11.000000",
            "timezone_type": 3,
            "timezone": "Europe/Berlin"
        },
        "fecha_ultimo_login": {
            "date": "2018-01-12 09:57:11.000000",
            "timezone_type": 3,
            "timezone": "Europe/Berlin"
        },
        "perfil": []
    },
    "ruta_foto": "/imgusers/default/",
    "errores": []
}

Why is the Profile class empty? can anybody help me? another thing that happens to me here is that the dates I must return them as an array because if I do this @Type ("DateTime < 'Y-m-d' >") they come empty. Any suggestions or help? thank you very much.

    
asked by polaries 12.01.2018 в 10:14
source

3 answers

0

Well, I got it with VirtualProperty:

namespace TaurusUrsusApiRest\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
//use Symfony\Component\Security\Core\User\UserInterface;
//use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Expose;

 /**
 * @ORM\Entity
 * @ORM\Table(name="usuario")
 *
 * @VirtualProperty(
 *     "perfil",
 *     exp="object.getPerfil()",
 *     options={@SerializedName("perfil")}
 *  )
 * 
 */
class Usuario {

/**
 * @var int
 * 
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 **/
private $id;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=false)
 */
private $email;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $username;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=false)
 */
private $password;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $salt;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $confirmationToken;

/**
 * @var boolean
 * 
 * @ORM\Column(type="boolean",nullable=false)
 */
private $activo = false;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $sessionId;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true, length=20)
 */
private $cifDni;

/**
 * @var string
 *
 * @ORM\Column(type="string",nullable=true, length=14)
*/
private $tlf;

/**
 * @Type("array")
 * @ORM\Column(name="fechaRegistro", type="datetime",nullable=true)
**/
private $fechaRegistro;

/**
 * @Type("array")
 * @ORM\Column(name="fechaUltimoLogin", type="datetime",nullable=true)
**/

//        * @Type("DateTime<'d-m-Y H:i:s'>")

private $fechaUltimoLogin;

//relacion entre el usuario y su perfil
/**
 * @Exclude
 * @Type("array")
 * @ORM\ManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
 * @ORM\JoinColumn(name="perfil", referencedColumnName="id")
 */
private $perfil;


/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set email
 *
 * @param string $email
 *
 * @return Usuario
 */
public function setEmail($email)
{
    $this->email = $email;

    return $this;
}

/**
 * Get email
 *
 * @return string
 */
public function getEmail()
{
    return $this->email;
}

/**
 * Set username
 *
 * @param string $username
 *
 * @return Usuario
 */
public function setUsername($username)
{
    $this->username = $username;

    return $this;
}

/**
 * Get username
 *
 * @return string
 */
public function getUsername()
{
    return $this->username;
}

/**
 * Set password
 *
 * @param string $password
 *
 * @return Usuario
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set salt
 *
 * @param string $salt
 *
 * @return Usuario
 */
public function setSalt($salt)
{
    $this->salt = $salt;

    return $this;
}

/**
 * Get salt
 *
 * @return string
 */
public function getSalt()
{
    return $this->salt;
}

/**
 * Set confirmationToken
 *
 * @param string $confirmationToken
 *
 * @return Usuario
 */
public function setConfirmationToken($confirmationToken)
{
    $this->confirmationToken = $confirmationToken;

    return $this;
}

/**
 * Get confirmationToken
 *
 * @return string
 */
public function getConfirmationToken()
{
    return $this->confirmationToken;
}

/**
 * Set activo
 *
 * @param boolean $activo
 *
 * @return Usuario
 */
public function setActivo($activo)
{
    $this->activo = $activo;

    return $this;
}

/**
 * Get activo
 *
 * @return boolean
 */
public function getActivo()
{
    return $this->activo;
}

/**
 * Set sessionId
 *
 * @param string $sessionId
 *
 * @return Usuario
 */
public function setSessionId($sessionId)
{
    $this->sessionId = $sessionId;

    return $this;
}

/**
 * Get sessionId
 *
 * @return string
 */
public function getSessionId()
{
    return $this->sessionId;
}

/**
 * Set cifDni
 *
 * @param string $cifDni
 *
 * @return Usuario
 */
public function setCifDni($cifDni)
{
    $this->cifDni = $cifDni;

    return $this;
}

/**
 * Get cifDni
 *
 * @return string
 */
public function getCifDni()
{
    return $this->cifDni;
}

/**
 * Set tlf
 *
 * @param string $tlf
 *
 * @return Usuario
 */
public function setTlf($tlf)
{
    $this->tlf = $tlf;

    return $this;
}

/**
 * Get tlf
 *
 * @return string
 */
public function getTlf()
{
    return $this->tlf;
}

/**
 * Set fechaRegistro
 *
 * @param \DateTime $fechaRegistro
 *
 * @return Usuario
 */
public function setFechaRegistro($fechaRegistro)
{
    $this->fechaRegistro = $fechaRegistro;

    return $this;
}

/**
 * Get fechaRegistro
 *
 * @return \DateTime
 */
public function getFechaRegistro()
{
    return $this->fechaRegistro;
}

/**
 * Set fechaUltimoLogin
 *
 * @param \DateTime $fechaUltimoLogin
 *
 * @return Usuario
 */
public function setFechaUltimoLogin($fechaUltimoLogin)
{
    $this->fechaUltimoLogin = $fechaUltimoLogin;

    return $this;
}

/**
 * Get fechaUltimoLogin
 *
 * @return \DateTime
 */
public function getFechaUltimoLogin()
{
    return $this->fechaUltimoLogin;
}


/**
 * Set perfil
 *
 * @param \TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil
 *
 * @return Usuario
 */
public function setPerfil(\TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil = null)
{
    $this->perfil = $perfil;

    return $this;
}

/**
 * Get perfil
 * @VirtualProperty()
 * @return \TaurusUrsusApiRest\MainBundle\Entity\Perfiles
 */
public function getPerfil()
{
    return $this->perfil;
}
}

I had to put * @Exclude in the relation $ profile, it must be that the variable of the relation and the name of the VirtualProperty can not have the same names

If I change the name to VirtualProperty and call it profileUsu, it works as well, but returns the profile twice:

{
"entity": {
    "perfilUsu": {
        "id": 1,
        "nombre_perfil": "Admin",
        "usuarios": [
            {
                "id": 52,
                "email": "[email protected]",
                "username": "Usuario desde postman",
                "password": "$2y$13$ZkJ2TSYxezB4NiVzVyotduWbifzUEcl6o0lnZJwWPKSk8uBL.bB7e",
                "salt": "fBvM&1{0x6%sW*-wH2;4y)6#6",
                "confirmation_token": "wSUccqb)^0y_yw3J}YEqypZ#=~x9k3",
                "activo": false,
                "fecha_registro": {
                    "date": "2018-01-12 15:43:50.000000",
                    "timezone_type": 3,
                    "timezone": "Europe/Berlin"
                },
                "fecha_ultimo_login": {
                    "date": "2018-01-12 15:43:50.000000",
                    "timezone_type": 3,
                    "timezone": "Europe/Berlin"
                }
            }
        ]
    },
    "perfil": {
        "id": 1,
        "nombre_perfil": "Admin",
        "usuarios": [
            {
                "id": 52,
                "email": "[email protected]",
                "username": "Usuario desde postman",
                "password": "$2y$13$ZkJ2TSYxezB4NiVzVyotduWbifzUEcl6o0lnZJwWPKSk8uBL.bB7e",
                "salt": "fBvM&1{0x6%sW*-wH2;4y)6#6",
                "confirmation_token": "wSUccqb)^0y_yw3J}YEqypZ#=~x9k3",
                "activo": false,
                "fecha_registro": {
                    "date": "2018-01-12 15:43:50.000000",
                    "timezone_type": 3,
                    "timezone": "Europe/Berlin"
                },
                "fecha_ultimo_login": {
                    "date": "2018-01-12 15:43:50.000000",
                    "timezone_type": 3,
                    "timezone": "Europe/Berlin"
                }
            }
        ]
    },
    "email": "[email protected]",
    "username": "Usuario desde postman",
    "password": "$2y$13$VWVJWSl5RyR.IypMdyV0MeUPC/RvZbJo5ioWyTayaMx/Fv0pc.8ni",
    "salt": "UeIY)yG$~#*Lw%t2dJrDwPkc*",
    "confirmation_token": "69WNGm}M41pQ~XEt30W1iS}zY-%|{&",
    "activo": false,
    "fecha_registro": {
        "date": "2018-01-12 16:08:27.000000",
        "timezone_type": 3,
        "timezone": "Europe/Berlin"
    },
    "fecha_ultimo_login": {
        "date": "2018-01-12 16:08:27.000000",
        "timezone_type": 3,
        "timezone": "Europe/Berlin"
    }
},
"ruta_foto": "/imgusers/default/",
"errores": []
}

Thank you very much Amenadiel you have opened my eyes.

    
answered by 12.01.2018 в 16:12
0

If I put a $ profile public:

/**
* @Type("array")
* @ORM\ManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
* @ORM\JoinColumn(name="perfil", referencedColumnName="id")
*/
public $perfil;

the answer is the same with the empty profile

But if I put this too:

/**
 * @Type("array")
 * @ORM\OneToMany(targetEntity="Usuario", mappedBy="perfil")
 */
public $usuarios;

The answer is:

{
"error": {
    "code": 500,
    "message": "Internal Server Error",
    "exception": [
        {
            "message": "Class ArrayCollection does not exist",
           "class": "ReflectionException",
....
....
}

}

I have to say that I return the objects of type array because that ArrayCollection error gives me to try to pass it without putting @ Type, and I do not have any idea why it could be, in a thread of the creator of JMSSerializerBundle there was talk of passing them as array and it has worked with dates, but with nothing relations.

Thank you very much.

    
answered by 12.01.2018 в 15:26
0

if I use virtualproperty:

<?php

namespace ....\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
//use Symfony\Component\Security\Core\User\UserInterface;
//use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Annotation\SerializedName;

 /**
 * @ORM\Entity
 * @ORM\Table(name="usuario")
 *
 * @VirtualProperty(
 *     "perfil",
 *     exp="object.getPerfil()",
 *     options={@SerializedName("perfil")}
 *  )
 * 
 */
class Usuario {

/**
 * @var int
 * 
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 **/
private $id;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=false)
 */
private $email;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $username;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=false)
 */
private $password;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $salt;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $confirmationToken;

/**
 * @var boolean
 * 
 * @ORM\Column(type="boolean",nullable=false)
 */
private $activo = false;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true)
 */
private $sessionId;

/**
 * @var string
 * 
 * @ORM\Column(type="string",nullable=true, length=20)
 */
private $cifDni;

/**
 * @var string
 *
 * @ORM\Column(type="string",nullable=true, length=14)
*/
private $tlf;

/**
 * @Type("array")
 * @ORM\Column(name="fechaRegistro", type="datetime",nullable=true)
**/
private $fechaRegistro;

/**
 * @Type("array")
 * @ORM\Column(name="fechaUltimoLogin", type="datetime",nullable=true)
**/

//        * @Type("DateTime<'d-m-Y H:i:s'>")

private $fechaUltimoLogin;

//relacion entre el usuario y su perfil
/**
 * @Type("array")
 * @ORM\ManyToOne(targetEntity="Perfiles",inversedBy="usuarios")
 * @ORM\JoinColumn(name="perfil", referencedColumnName="id")
 */
private $perfil;


/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set email
 *
 * @param string $email
 *
 * @return Usuario
 */
public function setEmail($email)
{
    $this->email = $email;

    return $this;
}

/**
 * Get email
 *
 * @return string
 */
public function getEmail()
{
    return $this->email;
}

/**
 * Set username
 *
 * @param string $username
 *
 * @return Usuario
 */
public function setUsername($username)
{
    $this->username = $username;

    return $this;
}

/**
 * Get username
 *
 * @return string
 */
public function getUsername()
{
    return $this->username;
}

/**
 * Set password
 *
 * @param string $password
 *
 * @return Usuario
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set salt
 *
 * @param string $salt
 *
 * @return Usuario
 */
public function setSalt($salt)
{
    $this->salt = $salt;

    return $this;
}

/**
 * Get salt
 *
 * @return string
 */
public function getSalt()
{
    return $this->salt;
}

/**
 * Set confirmationToken
 *
 * @param string $confirmationToken
 *
 * @return Usuario
 */
public function setConfirmationToken($confirmationToken)
{
    $this->confirmationToken = $confirmationToken;

    return $this;
}

/**
 * Get confirmationToken
 *
 * @return string
 */
public function getConfirmationToken()
{
    return $this->confirmationToken;
}

/**
 * Set activo
 *
 * @param boolean $activo
 *
 * @return Usuario
 */
public function setActivo($activo)
{
    $this->activo = $activo;

    return $this;
}

/**
 * Get activo
 *
 * @return boolean
 */
public function getActivo()
{
    return $this->activo;
}

/**
 * Set sessionId
 *
 * @param string $sessionId
 *
 * @return Usuario
 */
public function setSessionId($sessionId)
{
    $this->sessionId = $sessionId;

    return $this;
}

/**
 * Get sessionId
 *
 * @return string
 */
public function getSessionId()
{
    return $this->sessionId;
}

/**
 * Set cifDni
 *
 * @param string $cifDni
 *
 * @return Usuario
 */
public function setCifDni($cifDni)
{
    $this->cifDni = $cifDni;

    return $this;
}

/**
 * Get cifDni
 *
 * @return string
 */
public function getCifDni()
{
    return $this->cifDni;
}

/**
 * Set tlf
 *
 * @param string $tlf
 *
 * @return Usuario
 */
public function setTlf($tlf)
{
    $this->tlf = $tlf;

    return $this;
}

/**
 * Get tlf
 *
 * @return string
 */
public function getTlf()
{
    return $this->tlf;
}

/**
 * Set fechaRegistro
 *
 * @param \DateTime $fechaRegistro
 *
 * @return Usuario
 */
public function setFechaRegistro($fechaRegistro)
{
    $this->fechaRegistro = $fechaRegistro;

    return $this;
}

/**
 * Get fechaRegistro
 *
 * @return \DateTime
 */
public function getFechaRegistro()
{
    return $this->fechaRegistro;
}

/**
 * Set fechaUltimoLogin
 *
 * @param \DateTime $fechaUltimoLogin
 *
 * @return Usuario
 */
public function setFechaUltimoLogin($fechaUltimoLogin)
{
    $this->fechaUltimoLogin = $fechaUltimoLogin;

    return $this;
}

/**
 * Get fechaUltimoLogin
 *
 * @return \DateTime
 */
public function getFechaUltimoLogin()
{
    return $this->fechaUltimoLogin;
}


/**
 * Set perfil
 *
 * @param \TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil
 *
 * @return Usuario
 */
public function setPerfil(\TaurusUrsusApiRest\MainBundle\Entity\Perfiles $perfil = null)
{
    $this->perfil = $perfil;

    return $this;
}

/**
 * Get perfil
 * @VirtualProperty()
 * @return \TaurusUrsusApiRest\MainBundle\Entity\Perfiles
 */
public function getPerfil()
{
    return $this->perfil;
}
}

the answer changes a bit, but not much:

{
"entity": {
    "perfil": [],
    "id": 52,
    "email": "[email protected]",
    "username": "Usuario desde postman",
    "password": "$2y$13$ZkJ2TSYxezB4NiVzVyotduWbifzUEcl6o0lnZJwWPKSk8uBL.bB7e",
    "salt": "fBvM&1{0x6%sW*-wH2;4y)6#6",
    "confirmation_token": "wSUccqb)^0y_yw3J}YEqypZ#=~x9k3",
    "activo": false,
    "fecha_registro": {
        "date": "2018-01-12 15:43:50.000000",
        "timezone_type": 3,
        "timezone": "Europe/Berlin"
    },
    "fecha_ultimo_login": {
        "date": "2018-01-12 15:43:50.000000",
        "timezone_type": 3,
        "timezone": "Europe/Berlin"
    }
},
"ruta_foto": "/imgusers/default/",
"errores": []
}
    
answered by 12.01.2018 в 15:49