You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I receive XML objects that have empty tags, which in our application should be null.
However, the serializer serializes these properties as an empty string (""). This behaviour is being solved for several types (integers, etc.) in the AbstractObjectNormalizer.
My proposal is to add an option that also solves this when denormalizing nullable strings:
As long as setBar('') is allowed at the domain level, im not sure serializer should cast (or care for that matter). In this case the empty string should be handled at the domain level IMHO ($this->prop = '' === $v ? null : $v;)
DENORMALIZE_EMPTY_STRINGS_AS_NULL => true + non-nullable property could also be expected to crash IMHO
Regarding the use-case, this feature request somehow relates to #27933 which would enable and explicit this behavior per-property (with a normalizer function converting empty strings to null).
I don't agree this is something that should happen at the domain-level. The signature of the method allowing an empty string does not mean it is expected. At best it would reject, but it does not have to adapt to the input, especially when it's a source/tool related-issue. Instead, we should tell the tool how to adapt to the expectations (either the Serializer or the PropertyAccessor component in this case).
Description
I receive XML objects that have empty tags, which in our application should be
null
.However, the serializer serializes these properties as an empty string (""). This behaviour is being solved for several types (integers, etc.) in the AbstractObjectNormalizer.
My proposal is to add an option that also solves this when denormalizing nullable strings:
Example
Consider the following object class:
And the following XML
$data
:Or similar
When this data is deserialized using (current situation):
We get a
SomeClass
object, with:foo = ""
(empty string)bar = ""
(empty string)When we add the option to the context (proposed feature):
The result should be a
SomeClass
object, with:foo = ""
(empty string, because not nullable)bar = null
(because nullable)The text was updated successfully, but these errors were encountered: