After update to 2.4 version some of ItemNormilizers not used to normalize some object properties.
As example, I have two jsonld item normilizers PropertyItemNormalizer and TechnologyPropertyNormalizer.
TechnologyPropertyNormalizer decorates normalization of some class:
``` {
"@id": "/api/technologies/07957bf6-4917-4f89-b697-28786520ad96",
"@type": "Technology",
"id": "07957bf6-4917-4f89-b697-28786520ad96",
"code": "KoTest",
"name": "techTest",
"description": "DescTest",
"factoryProducts": [],
"properties": [
{
"@id": "/api/technology_properties/d064ec0c-32d2-46f8-b1b4-7d8224ea0a15",
"@type": "TechnologyProperty",
"id": "d064ec0c-32d2-46f8-b1b4-7d8224ea0a15",
"required": false,
"code": "animal",
"name": "Animal",
"values": [
"Mouse"
]
}
],
"createdAt": "2019-02-26T13:11:46+01:00",
"updatedAt": "2019-02-26T13:11:46+01:00"
}
The properties "code","name" and "values" TechnologyPropertyNormalizer takes from entity relationships.
And after update this item nozrmilizer not working and the normalized entity looks like this:
``` {
"@id": "/api/technologies/07957bf6-4917-4f89-b697-28786520ad96",
"@type": "Technology",
"id": "07957bf6-4917-4f89-b697-28786520ad96",
"code": "KoTest",
"name": "techTest",
"description": "DescTest",
"factoryProducts": [],
"properties": [
{
"@id": "/api/technology_properties/d064ec0c-32d2-46f8-b1b4-7d8224ea0a15",
"@type": "TechnologyProperty",
"id": "d064ec0c-32d2-46f8-b1b4-7d8224ea0a15",
"required": false
}
],
"createdAt": "2019-02-26T13:11:46+01:00",
"updatedAt": "2019-02-26T13:11:46+01:00"
}
but it doesn't matter
during debbugin found that TechnologyPropertyNormalizer randomly not used for some obejct properties
Can you provide a failing Behat test? I think it'd be easier to understand the issue that way. :smile:
Do you have priorities on these custom normalizers ?
Failing scenario
Scenario: Create Technology
When I add "Content-Type" header equal to "application/ld+json"
And I add "Accept" header equal to "application/ld+json"
And I send a "POST" request to "/api/technologies" with body:
"""
{
"code": "sample_code_1",
"name": "Sample technology",
"description": "Sample technology",
"properties": [
{
"property": "/api/properties/6",
"possibilities": [
"/api/property_possibilities/1",
"/api/property_possibilities/2"
],
"required": true
},
{
"property": "/api/properties/2",
"possibilities": [],
"required": false
}
]
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should match to:
"""
{
"@context": "/api/contexts/Technology",
"@id": "@[email protected]('/api/technologies/')",
"@type": "Technology",
"id": "@uuid@",
"code": "sample_code_1",
"name": "Sample technology",
"description": "Sample technology",
"factoryProducts": [],
"properties": [
{
"@id": "@[email protected]('/api/technology_properties/')",
"@type": "TechnologyProperty",
"id": "@uuid@",
"required": true,
"code": "bar",
"name": "abc",
"values": [
"abcx",
"abcd"
]
},
{
"@id": "@[email protected]('/api/technology_properties/')",
"@type": "TechnologyProperty",
"id": "@uuid@",
"required": false,
"code": "printer",
"name": "Printer",
"values": []
}
],
"createdAt": "@[email protected]()",
"updatedAt": "@[email protected]()"
}
"""
Fails becouse got
{
"@context": "/api/contexts/Technology",
"@id": "@[email protected]('/api/technologies/')",
"@type": "Technology",
"id": "@uuid@",
"code": "sample_code_1",
"name": "Sample technology",
"description": "Sample technology",
"factoryProducts": [],
"properties": [
{
"@id": "@[email protected]('/api/technology_properties/')",
"@type": "TechnologyProperty",
"id": "@uuid@",
"required": true
},
{
"@id": "@[email protected]('/api/technology_properties/')",
"@type": "TechnologyProperty",
"id": "@uuid@",
"required": false
}
],
"createdAt": "@[email protected]()",
"updatedAt": "@[email protected]()"
instead of specyfied
Do you have priorities on these custom normalizers ?
nope
@AndriiMz Please, could you add a failing Behat test in our test suite? :smile: I think it'll move us closer to identifying the problem and to a fix.
Very interested in this problem too. I also have attributes with serialization that randomly disappear....
And this problem was not present before my upgrade to version 2.4.0
@baudev Please, could you help us add a failing Behat test in our test suite? :smile: I think it'll be a great help in identifying the problem and moving us closer to a fix.
@baudev Could you check if https://github.com/api-platform/core/pull/2679 fixes your issue?
Sorry @teohhanhui for not responding quickly. My computer just died two days ago. Still waiting to get it repaired... When I get a working computer again (or a new one :cry: ) I will test your PR, but I hope you will fix it before! Meanwhile, good luck :crossed_fingers:
This isn't just jsonld. It is any serializer. Having the same problem with #2681
@trsteel88 Please, help us add a failing Behat test to our test suite. It'll move things along much quicker. :smile:
I recovered my laptop yesterday and I have updated my project to 2.4.2. The bug has disappeared!
This is still appearing for me on latest 2.4 dev and very latest symfony release (4.2.6).
@teohhanhui I'm not familiar with Behat and a little short on time at the moment. I'll just need to hold off on a sf update for now.
I'm still having trouble.
@teohhanhui, I'm not sure how to write the behat tests you're after. I have setup a project here which illustrates the problem:
https://github.com/trsteel88/API-Platform-Serializer-Issue
This serializer is no longer attaching the custom attributes: https://github.com/trsteel88/API-Platform-Serializer-Issue/blob/master/src/Api/Serializer/ProjectSerializer.php
Most helpful comment
I recovered my laptop yesterday and I have updated my project to
2.4.2. The bug has disappeared!