Skip to content

Fix denormalization of basic property-types in XML and CSV#3191

Closed
warslett wants to merge 2 commits into
api-platform:2.6from
BiffBangPow:deserialize-xml-non-string-values
Closed

Fix denormalization of basic property-types in XML and CSV#3191
warslett wants to merge 2 commits into
api-platform:2.6from
BiffBangPow:deserialize-xml-non-string-values

Conversation

@warslett

Copy link
Copy Markdown
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tickets fixes https://github.com/api-platform/api-platform/issues/1299
License MIT

This PR fixes an issue where by posting XML content throws errors when a field has a non string primitive type because the XML encoder can only normalize primitive values as strings. This means that post create and update requests fail. This PR adds some additional behaviour where by the AbstractItemNormalizer will cast valid strings as the correct type.

@warslett warslett force-pushed the deserialize-xml-non-string-values branch from 4a49ff9 to 8ce220e Compare October 18, 2019 17:38
@warslett warslett force-pushed the deserialize-xml-non-string-values branch from 8ce220e to ff18160 Compare October 18, 2019 17:41
@teohhanhui

Copy link
Copy Markdown
Contributor

This is not the correct approach. The type cast feature should be added to Symfony Serializer. It should be controlled by a flag in the context.

@warslett

Copy link
Copy Markdown
Author

@teohhanhui that was my initial thinking aswell. The problem is that the AbstractObjectNormalizer handles this behaviour in the Serializer component and is extended by AbstractItemNormalizer in the API Platform. AbstractObjectNormalizer resolves types using an optional dependency called PropertyTypeExtractor but AbstractItemNormalizer overrides the constructor of AbstractObjectNormalizer and does not inject this dependency. Instead, AbstractItemNormalizer has a dependency on a different service PropertyMetadataFactory which can be used to determine types.

This means that AbstractItemNormalizer used with API Platform has a completely different mechanism for resolving types than AbstractObjectNormalizer when used with vanilla Serializer component. Therefor this problem needs to be solved separately in the Serializer component and the API Platform. This is not ideal but is due to the way inheritance has been used.

@warslett

Copy link
Copy Markdown
Author

#3192 (comment)

@teohhanhui

Copy link
Copy Markdown
Contributor

Yes, I get what you mean, but I think we should fix this in Symfony first. Then we can see how we'll fix it in API Platform. (Probably by calling the same methods from Symfony Serializer.)

@alanpoulain alanpoulain changed the base branch from 2.5 to 2.6 March 19, 2021 11:11
@alanpoulain alanpoulain changed the title Deserialize xml non string values Fix denormalization of basic property-types in XML and CSV Mar 19, 2021
@alanpoulain

Copy link
Copy Markdown
Member

Superseded by #4145.

@alanpoulain

Copy link
Copy Markdown
Member

Thank you @warslett.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants