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
As of 3.31.0, if you try to serialize a method that is a union type between a class a boolean value type (e.g. MyClass|false), JMS Serializer raises an exception.
I'm happy to raise a PR for this, but I'm not very familiar with the nuances of the codebase so I'm not confident this won't cause other issues.
The text was updated successfully, but these errors were encountered:
gregtyler
changed the title
Error serialising union types between class and boolean value types
Error serializing union types between class and boolean value types
Nov 11, 2024
Allows serialization of value types (i.e. `true` and `false`, as opposed to `bool`), including in union types (e.g. `string|false`).
Otherwise, tries to create class with FQCN "true" and, for union types, filters out value types as non-primitive.
Fixesschmittjoh#1568
Thanks, I've created #1569. In doing so I realised that it also doesn't work for non-union value types, so I've generalised the PR slightly to acknowledge that.
As of 3.31.0, if you try to serialize a method that is a union type between a class a boolean value type (e.g.
MyClass|false
), JMS Serializer raises an exception.This is because the value type is filtered out by
TypedPropertiesDriver->shouldTypeHint()
(becausetrue
andfalse
aren't in the allowlist) so the only acceptable value becomes "MyClass".Steps required to reproduce the problem
Expected Result
{"falsable_prop":false}
Actual Result
Exception thrown:
Workarounds
Changing the typehint to
MyClass|bool
fixes this, though means you're opening your type wider than needed.Fix
I believe this can be fixed with two changes:
'true'
and'false'
to the TypedPropertiesDriver whitelist'true'
and'false'
as cases to the graph navigator boolean acceptor (without, the navigator treats value types as objects)I'm happy to raise a PR for this, but I'm not very familiar with the nuances of the codebase so I'm not confident this won't cause other issues.
The text was updated successfully, but these errors were encountered: