i have an order entity which displays a company and paymentStates. Now im confused. When i fetch an order the company is displayed as object and the paymentStates as iri.
example response:
"company": {
"@id": "/api/companies/d3b832a9-35e3-4f50-bba6-98bb2646e161",
"@type": "Company",
"id": "d3b83xyz-35e3-4f50-0815-98bb2646e161",
"name": "Blubb",
"businessType": "company",
"email": "[email protected]"
},
"paymentStates": [
"/api/payment_states/10",
"/api/payment_states/11",
"/api/payment_states/12"
]
//....
I have no idea why at this point i get only the iri. The api platform declaration of both files as following:
//Company
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
collectionOperations: ["get"]
)]
class Company
{
#[Groups(["read"])]
private $name;
}
//paymentState
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']]
)]
class PaymentState
{
#[Groups(["read", "write"])]
private $created;
}
Where is the different and how i can decide to what to show, because sometimes i need an iri but i get an arry or object. Thanks for your help
CodePudding user response:
Do you have #[Groups(["read"])]
attribute, on paymentState
property in the Company
class?
CodePudding user response:
I found the solution and it was a very stupid mistake.
The class use Symfony\Component\Serializer\Annotation\Groups;
wasn't imported and the php8 annotation #[Groups(["read"])]
wasn't called.
The strangest thing at this point is, that symfony dont throw an exception, thatswhy u have to look closely if this class was really imported.