Closed
Description
I have a pet owner:
<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="MWS\NutritionCalculatorBundle\Entity\PetOwner">
<attribute name="access_control">is_granted('ROLE_MWS_NC_GUEST')</attribute>
<attribute name="client_items_per_page">true</attribute>
<attribute name="items_per_page_parameter_name">itemsPerPage</attribute>
<property name="pets">
<subresource resourceClass="MWS\NutritionCalculatorBundle\Entity\Pet" maxDepth="1" collection="true"/>
</property>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>mws_nc_pet_owner_read</attribute>
</attribute>
</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>mws_nc_pet_owner_write</attribute>
</attribute>
</attribute>
<collectionOperations>
<collectionOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_LIST')</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_pet_owner_read</attribute>
</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="post">
<attribute name="method">POST</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_CREATE')</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_pet_owner_write</attribute>
</attribute>
</attribute>
<attribute name="validation_groups">
<attribute>PetOwner</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_VIEW')</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_pet_owner_read</attribute>
</attribute>
</attribute>
</itemOperation>
<itemOperation name="put">
<attribute name="method">PUT</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_EDIT')</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_pet_owner_write</attribute>
</attribute>
</attribute>
<attribute name="validation_groups">
<attribute>PetOwner</attribute>
</attribute>
</itemOperation>
<itemOperation name="delete">
<attribute name="method">DELETE</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_DELETE')</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_pet_owner_delete</attribute>
</attribute>
</attribute>
</itemOperation>
</itemOperations>
</resource>
</resources>
And there is a subresource (pets belong to the pet owner):
<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="MWS\NutritionCalculatorBundle\Entity\Pet">
<attribute name="access_control">is_granted('ROLE_MWS_NC_GUEST')</attribute>
<attribute name="pagination_client_enabled">true</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>mws_nc_pet_read</attribute>
</attribute>
</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>mws_nc_pet_write</attribute>
</attribute>
</attribute>
<collectionOperations>
<collectionOperation name="api_pet_owners_pets_get_subresource">
<attribute name="method">GET</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>mws_nc_pet_list</attribute>
</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="sex_type_choices">
<attribute name="method">GET</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_LIST')</attribute>
<attribute name="path">pets/sex_type_choices</attribute>
<attribute name="controller">MWS\NutritionCalculatorBundle\Controller\SexTypeChoices</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_sex_type_choices_read</attribute>
</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="protein_albumin_total_choices">
<attribute name="method">GET</attribute>
<attribute name="access_control">is_granted('ROLE_MWS_NC_LIST')</attribute>
<attribute name="path">/pets/protein_albumin_total_choices</attribute>
<attribute name="controller">MWS\NutritionCalculatorBundle\Controller\ProteinAlbuminTotalChoices</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute name="group">mws_nc_protein_albumin_total_choices_read</attribute>
</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations/>
<subresourceOperations/>
</resource>
</resources>
The serialization groups of the pet entity is:
<?xml version="1.0" encoding="UTF-8" ?>
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping
http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="MWS\NutritionCalculatorBundle\Entity\Pet">
<attribute name="name">
<group>mws_nc_pet_list</group>
<group>mws_nc_recipe_cat_view</group>
<group>mws_nc_recipe_dog_view</group>
</attribute>
<attribute name="sex">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="birthday">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="species">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="breed">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="diagnosis">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="currentWeight">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="targetWeight">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="petOwner">
<group>mws_nc_pet_list</group>
</attribute>
<attribute name="sexTypeChoices">
<group>mws_nc_sex_type_choices_read</group>
</attribute>
<attribute name="proteinAlbuminTotalChoices">
<group>mws_nc_protein_albumin_total_choices_read</group>
</attribute>
</class>
</serializer>
After the update to APIP 2.4 I only get the iris and the types of the pets. The properties are not serialized anymore. Now the serialization group of the entity level (mws_nc_pet_read
) is assigned to serialization instead of the one of the operation level (mws_nc_pet_list
).
So what I get ist:
{
"@context": "/api/contexts/Pet",
"@id": "/api/pet_owners/1/pets",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "/api/dogs/1",
"@type": "Dog"
},
{
"@id": "/api/dogs/2",
"@type": "Dog"
},
{
"@id": "/api/cats/3",
"@type": "Cat"
}
],
"hydra:totalItems": 3
}
Before the update I got:
{
"@context": "/api/contexts/Pet",
"@id": "/api/pet_owners/1/pets",
"@type": "hydra:Collection",
"hydra:member": [
{
"@id": "/api/dogs/1",
"@type": "Dog",
"breed": null,
"name": "Romy",
"sex": 0,
"birthday": "2018-05-21T14:25:33+02:00",
"diagnosis": "DOG_DIAGNOSIS_GROWTH",
"currentWeight": 10,
"targetWeight": 10,
"petOwner": "/api/pet_owners/1",
"species": "Hund"
},
{
"@id": "/api/dogs/2",
"@type": "Dog",
"breed": "/api/dog_breeds/2",
"name": "Anton",
"sex": 1,
"birthday": "2014-08-14T00:00:00+02:00",
"diagnosis": "DOG_DIAGNOSIS_SENIOR",
"currentWeight": 25,
"targetWeight": 20,
"petOwner": "/api/pet_owners/1",
"species": "Hund"
},
{
"@id": "/api/cats/3",
"@type": "Cat",
"breed": null,
"name": "Mimi",
"sex": 0,
"birthday": "2006-09-19T17:42:14+02:00",
"diagnosis": "CAT_DIAGNOSIS_SENIOR",
"currentWeight": 5,
"targetWeight": 5,
"petOwner": "/api/pet_owners/1",
"species": "Katze"
}
],
"hydra:totalItems": 3
}
Another one is that a change one serialization group it took effect immediately in dev environment. Now I have to clear the cache to see the changes.