Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If none of the nested object's properties are part of serialization groups, array is returned instead of null #6306

Open
ostrolucky opened this issue Apr 11, 2024 · 0 comments

Comments

@ostrolucky
Copy link
Contributor

ostrolucky commented Apr 11, 2024

API Platform version(s) affected: 3.2.18

Description
If object is part of the correct serialization group, but nested object doesn't have this group assigned, nested object is serialized as empty array. Instead, I would expect exception to be thrown or null returned instead of array

How to reproduce
Given code

class Foo {
  public __construct(#[Groups('groupA')] public Bar $bar) {}
}
class Bar {
  public __construct (#[Groups('groupB')] public string $baz) {};
}

And return new Foo(new Bar('baz')); with groupA as serialization group, APIP will serialize it like so {"foo": {"bar": []}}. Instead, I expect it will serialize it like {"foo": {"bar": null}}, since serializing this as array breaks OpenAPI contract

Possible Solution
Throw exception, or return null

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

No branches or pull requests

1 participant