I\'m trying to serialize a entity relation with JMS Serializer.
Here is the Entity:
class Ad
{
/**
* @Type(\"string\")
* @Groups({\"manag
Alternatively, you can @inline
$country
which will serialize its properties into the parent relation. Then you can @Expose
the Country $id
and set its @SerializedName
to "country"
. Unlike Virtual properties, both serialization and deserialization will work for inline properties.
For this to work, you need to use the @ExclusionPolicy("All")
on each class and judiciously @Expose
the properties that you need in any of your groups. This is a more secure policy anyways.
/**
* @ExclusionPolicy("All")
*/
class Ad
{
//...
/**
* @Type("Acme\SearchBundle\Entity\Country")
*
* @Expose()
* @Inline()
* @Groups({"manage"})
*
* @var \Acme\SearchBundle\Entity\Country
*/
private $country;
//...
}
/**
* @ExclusionPolicy("All")
*/
class Country
{
//...
/**
* Get id
*
* @Expose()
* @Groups({"manage"})
* @SerializedName("country")
* @return string
*/
public function getId()
{
return $this->id;
}
}