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

bug: removeNullProperties in JSONSerializer removes non-recursive arrays #421

Open
mgkimsal opened this issue Aug 19, 2021 · 1 comment
Open

Comments

@mgkimsal
Copy link

mgkimsal commented Aug 19, 2021

#420

I've seen others with the same error messages I was seeing yesterday

"CustomerRef is missing" from posting an Invoice object.

Using JSON, the serializer 'removeNullProperties' method was filtering out the "CustomerRef" key/value, because the value itself was not a 'recurrsiveArray' (typo there - wasn't sure if I should change that too?)

Added a test to validate/demonstrate what I need (and assume should be correct behavior).

If there's a better way to fix this, please let me know.

I can't be the only one who's hit this, but... I've also been able to simply create an invoice for a customer for 2 days now, and traced it down to this.

@mgkimsal
Copy link
Author

Looking at this more, I'm guessing more people use a 'loose collection' style... ?

Invoice::create([
  'CustomerRef'=>['value'=>58],
  'Lines'=>[],// etc
]);

and perhaps this wasn't/isn't a problem?

I was/am using code more like this...

        $customerRef = new IPPReferenceType();
        $customerRef->value = $qbCustomer->Id;
        $customerRef->name = $qbCustomer->FullyQualifiedName;

        $qbInvoice = new IPPInvoice();
        $qbInvoice->CustomerRef = $customerRef;
...
        $qbInvoice->Lines = []; // multiple IPPLines there
        $quickbooks->Add($qbInvoice);

This is where I kept getting "CustomerRef is missing" errors, because the Add() call something that eventually gets down to a serializer - XML or JSON. The XML one never worked for me...

Trying to get property 'CustomLogger' of non-object in .../vendor/quickbooks/v3-php-sdk/src/Core/Http/Serialization/XmlObjectSerializer.php

When I discovered you could swap with ->useJson() it seemed to get much farther than that, and I got real 'error messages' back - I tried to dig in to the XmlObjectSerializer.php a bit more but... there's some magic going on there that I couldn't get past.

This was a problem for me on both PHP 7.4.20 and 8.0.6. The 'fix' I have works in both cases.

@mgkimsal mgkimsal changed the title bug: removeNullProperties removes regular arrays too bug: removeNullProperties removes non-recursive arrays Aug 20, 2021
@mgkimsal mgkimsal changed the title bug: removeNullProperties removes non-recursive arrays bug: removeNullProperties in JSONSerializer removes non-recursive arrays Aug 20, 2021
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