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

Is there any way to override keys _links & _embedded in the JsonHalSerializer #175

Open
abhisheksavant opened this issue Nov 24, 2014 · 2 comments
Labels

Comments

@abhisheksavant
Copy link

/**
 * @author Adrien Brault <adrien.brault@gmail.com>
 */
class JsonHalSerializer implements JsonSerializerInterface
{
    /**
     * {@inheritdoc}
     */
    public function serializeLinks(array $links, JsonSerializationVisitor $visitor, SerializationContext $context)
    {
       ...........
        $visitor->addData('_links', $serializedLinks);
    }

    /**
     * {@inheritdoc}
     */
    public function serializeEmbeddeds(array $embeddeds, JsonSerializationVisitor $visitor, SerializationContext $context)
    {
        ........
        $visitor->addData('_embedded', $serializedEmbeddeds);
    }
}

In my project I wanted to customize '_link' and 'embedd' key words. One solution is to extend JsonHalSerializer to a custom serializer and then use the setJsonSerializer method. Is there any other simpler way to do this without overriding JsonHalSerializer.

@adrienbrault
Copy link
Contributor

I don't see any other way.

The library could split the serializeLinks and serializeEmbeddeds methods and introduce protected methods:

class JsonHalSerializer
{
    public function serializeLinks(...)
    {
        $visitor->addData('_links', $this->getLinks());
    }
    public function serializeEmbeddeds(...)
    {
        $visitor->addData('_embedded', $this->getEmbedded());
    }

    protected function getLinks(){}
    protected function getEmbedded(){}
}

which would make extension easier

@adrienbrault
Copy link
Contributor

@abhisheksavant What is your use case ?

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

3 participants