bitgandtter
bitgandtter

Reputation: 2329

symfony hateoas and jms serialization

I have an entity Customer that i want to have both Hatoas Links and custom serialization

/**
 * Customer ORM Entity
 *
 * @package AppBundle\Entity
 *
 * @Hateoas\Relation("self", href = @Hateoas\Route("get_customers", parameters = { "customer" = "expr(object.getId())" }))
 * @Hateoas\Relation("customers", href = @Hateoas\Route("cget_customers"))))
 */

That is the annotation for the hateoas links

AppBundle\Entity\Customer:
    exclusion_policy: ALL
    virtual_properties:
        getFullName:
            serialized_name: full_name
            type: string

That is my yaml configuration for the jms serialization but for some reason it also remove the hateoas links.

How can i get it back? Tell to the serializer to not remove the _links property?

Upvotes: 2

Views: 1062

Answers (2)

Matteo
Matteo

Reputation: 39430

As @takeit say, you should use the same configuration used with the serializer. For your example try this:

AppBundle\Entity\Customer:
    exclusion_policy: ALL
    virtual_properties:
        getFullName:
            serialized_name: full_name
            type: string
    relations:
        -
        href:
          route: get_customers
          parameters:
              customer: expr(object.getId())
  #       absolute: 0
        customers:
          route: cget_customers

Hope this help

Upvotes: 2

takeit
takeit

Reputation: 4081

In Hateoas documentation it says:

Important: you must configure both the Serializer and Hateoas the same way. E.g. if you use YAML for configuring Serializer, use YAML for configuring Hateoas.

For example, use the YAML format for configuration and your issue should be solved.

Upvotes: 3

Related Questions