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

Virtual property having type overriden by doctrine metadata #276

Closed
cblegare opened this issue May 22, 2014 · 1 comment
Closed

Virtual property having type overriden by doctrine metadata #276

cblegare opened this issue May 22, 2014 · 1 comment
Labels

Comments

@cblegare
Copy link

Say I have a doctrine entity

/**
 * @Entity
 * @Table(name="some_table")
 */
class SomeEntity {
    /** @Column(type="blob") */
    protected $someObject;

    /**
     * @return SomeType
     */
    public function getSomeObject()
    {
        // ... unserialize $this->someObject to $unserializedObject
        /** @var SomeType $unserializedObject */
        return $unserializedObject
    }
}

And the following Serializer configuration :

SomeEntity:
    access_type: public_method
    virtual_properties:
        getSomeObject:
            serialized_name: someObject

Note that no type is specified in the virtual_properties configuration for getSomeObject. I expect the JMSSerializer to infer the type (SomeType) using the return value of getSomeObject.

But this is not happening. Instead, even if it is a virtual property, it fetches the type from Doctrine metadata of the property having a related name ($someObject) and cast is as a string because blobis considered string by the DoctrineDriver. See https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/Metadata/Driver/DoctrineTypeDriver.php#L47.

The issue is : why should a doctrine type driver be used in case of a virtual property ? I can work around this issue renaming the property to something funny :

class SomeEntity {
    /** 
     * This property has a funny name because JMSSerializer has a funny behavior
     *
     * @Column(type="blob")
     */
    protected $someObjectTotoFooBarFunnyNameHuh;

    /**
     * @return SomeType
     */
    public function getSomeObject()
    {
        // ... unserialize $this->someObjectTotoFooBarFunnyNameHuh to $unserializedObject
        /** @var SomeType $unserializedObject */
        return $unserializedObject
    }
}

Did I missed something or is it pure nonsense ?

@goetas
Copy link
Collaborator

goetas commented Mar 21, 2017

solved with afe0e40 and will be released with v1.6

@goetas goetas closed this as completed Mar 21, 2017
@goetas goetas added the bug label Mar 21, 2017
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