Strange Api-platform activity. It looks like ApiProperty Attribute doesn’t work with json format. Why? And how to make ApiProperty to work on json too.
I have simple ApiResource example
#[ApiResource()]
class UserApi
{
public ?int $id = null;
public ?string $firstName = null;
#[ApiProperty(readable: false)]
public ?string $doNotShow = null;
}
If i request jsonld format http://localhost/api/users/1.jsonld
, i get:
{
"@context": "/api/contexts/User",
"@id": "/api/users/1",
"@type": "User",
"id": 1,
"firstName": "john",
}
If i request json format http://localhost/api/users/1.json
, i get:
{
"id": 1,
"firstName": "john",
"doNotShow": "secret",
}
PHP 8.2, Symfony 7, “api-platform/core”: “3.3.2”,
config file: api_platform.yaml
api_platform:
mapping:
paths: [
'%kernel.project_dir%/src/Entity',
]
formats:
json: [ 'application/json' ]
jsonld: ['application/ld+json']