Hateoas icon indicating copy to clipboard operation
Hateoas copied to clipboard

Links get rendered multiple times

Open Duske opened this issue 10 years ago • 1 comments

Hey guys,

does someone has had the problem that a link configured as an annotation gets rendered more than once? Do I need to configure something?

For example: renderer:

$this->hateoas = HateoasBuilder::create()->build();
$bookDto = new BookDto('mybook', '7343-3243-3243');
echo $this->hateoas->serialize($bookDto, 'json');

the output

{
    "__identity": "7343-3243-3243",
    "name": "mybook",
    "_links": {
        "self": [
            {
                "href": "books/7343-3243-3243"
            },
            {
                "href": "books/7343-3243-3243"
            }
        ]
    }
}

The class:

<?php

use TYPO3\Flow\Annotations as Flow;
use JMS\Serializer\Annotation as Serializer;
use Hateoas\Configuration\Annotation as Hateoas;

/**
* @Hateoas\Relation("self", href = "expr('books/' ~ object.getIdentifier())")
*/
class BookDto {

    /**
    * @var string
    */
    protected $__identity;

    /**
    * @var string
    */
    protected $name;

    /**
     * @return string
     */
    public function getName() {

        return $this->name;
    }

    /**
     * @return string
     */
    public function getIdentifier() {

        return $this->__identity;
    }

    /**
    * @param string $name
    * @param string $__identity
    */
    public function __construct($name, $__identity = NULL) {
        $this->__identity = $__identity;
        $this->name       = $name;
    }
}

Duske avatar May 10 '15 18:05 Duske

Is there any update on this? I have an similar issue on a class with an RelationProvider. I am sure the relationprovider adds the relation only once, but in some conditions the link is added multiple times in the serialized result.

Problem found In my case, the annotations where cached. Clearing the cache solved the problem.

jurrianvaniersel avatar Mar 27 '18 12:03 jurrianvaniersel