Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@VirtualProperty "exp" does not play nice with @ExclusionPolicy("ALL") #746

Closed
JustBlackBird opened this issue Apr 17, 2017 · 2 comments
Closed
Labels

Comments

@JustBlackBird
Copy link
Contributor

JustBlackBird commented Apr 17, 2017

I'm trying to solve problem similar to #448.

I have Department class:

class Department
{
    private $id;

    public function __construct($id)
    {
        $this->$id = $id;
    }

    public function getId()
    {
        return $this->id;
    }
}

If I define User class like this

/**
 * @Serializer\ExclusionPolicy("ALL")
 * @Serializer\VirtualProperty(
 *     "dep",
 *     exp="object.getDepartment().getId()",
 *     options={@Serializer\SerializedName("dep")}
 * )
 */
class User
{
    private $id;
    private $department;

    public function __construct($id, Department $department)
    {
        $this->id = $id;
        $this->department = $department;
    }

    /**
     * @Serializer\VirtualProperty()
     * @Serializer\SerializedName("id")
     */
    public function getId()
    {
        return $this->id;
    }

    public function getDepartment()
    {
        return $this->department;
    }
}

then after serialization i get something like:

{"id": 42}

Notice there is no dep field.

At the same time, if I define User as this:

/**
 * @Serializer\VirtualProperty(
 *     "dep",
 *     exp="object.getDepartment().getId()",
 *     options={@Serializer\SerializedName("dep")}
 * )
 */
class User
{
    /**
     * @Seializer\Exclude()
     */
    private $id;
    /**
     * @Seializer\Exclude()
     */
    private $department;

    public function __construct($id, Department $department)
    {
        $this->id = $id;
        $this->department = $department;
    }

    /**
     * @Serializer\VirtualProperty()
     * @Serializer\SerializedName("id")
     */
    public function getId()
    {
        return $this->id;
    }

    public function getDepartment()
    {
        return $this->department;
    }
}

I get

{"id": 42, "dep": 12}

It seems that @ExclusionPolicy("ALL") somehow breaks virtual properties based on expression language.

Am I missing something?

@goetas goetas closed this as completed in 5f9eed0 Apr 17, 2017
@goetas goetas added the bug label Apr 17, 2017
@goetas
Copy link
Collaborator

goetas commented Apr 17, 2017

thanks for the bug report, has been fixed in 1.6.2

@JustBlackBird
Copy link
Contributor Author

Thank you for the fix 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants