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
If I pass empty Generator to json normalizer, I have {data: {}} in response, but I expect to get {data: []}.
Let's look at \CuyZ\Valinor\Normalizer\Transformer\RecursiveTransformer::defaultTransformer
You make tranformation of generator and check - is it closed or not, if closed - you return empty object, but why?
if (is_iterable($value)) {
...
if (! $result->valid()) {
return EmptyObject::get();
}
return $result;
}
Empty generator at response is empty list, isn't it?
How about to replace into
if (! $result->valid()) {
return [];
}
Than response is as expected - just {data: []}.
Btw, removing JSON_FORCE_OBJECT from constructor of JsonNormalizer doesn't resolve the issue.
The text was updated successfully, but these errors were encountered:
I ran into this myself the other day. We use classes that extends ArrayObject for collections. If it's empty the normalizer returns an empty object instead of an empty array.
The problem here is that both ['foo' => 'bar'] and ['foo'] are iterable.
You'd expect an empty object for the first one and an empty array for the second one.
If I pass empty Generator to json normalizer, I have
{data: {}}
in response, but I expect to get{data: []}
.Let's look at
\CuyZ\Valinor\Normalizer\Transformer\RecursiveTransformer::defaultTransformer
You make tranformation of generator and check - is it closed or not, if closed - you return empty object, but why?
Empty generator at response is empty list, isn't it?
How about to replace into
Than response is as expected - just
{data: []}
.Btw, removing
JSON_FORCE_OBJECT
from constructor ofJsonNormalizer
doesn't resolve the issue.The text was updated successfully, but these errors were encountered: