Closed oprypkhantc closed 1 year ago
Interesting. I get a totally different error when I setup a test case for it. :smile: Possibly because I'm using master
and not 0.6.0, and there have been some changes to null handling since. Can you try with the latest master
and see what happens?
Yep. With dev-master
it works, awesome :) Moreover, all keys are now included in the serialized JSON, which definitely makes more sense to me. Thank you.
You mentioned you're getting a different error now; feel free to close this issue if it's unrelated.
More null edge cases handled in #30. I'll merge that shortly, which will close this issue. Thanks for the report.
Detailed description
When using the
#[Field(flatten: true)]
on a property of type that has a nullable property, it fails with with aTypeError
.Here's a tiny reproduction:
Context
It does not happen when serializing the nested class directly:
Possible implementation
Seems like it's caused by a missing check in
ObjectExporter
. RegularObjectExporter::flattenValue
checks whether given value is null, and if so - doesn't add a newCollectionItem
so that field is never serialized. In the case of a flatten value, however,ObjectExporter::reduceObjectProperty()
is used instead for some reason, which doesn't have a null check.If I remove
ObjectExporter::reduceObjectProperty()
and replace it with directflattenValue()
calls, it works as expected, but I'm not sure why it was implemented that way in the first place.Your environment