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

Deserializing an array of UuidInterface doesn't work #12

Closed
christian-kolb opened this issue Jul 15, 2020 · 9 comments
Closed

Deserializing an array of UuidInterface doesn't work #12

christian-kolb opened this issue Jul 15, 2020 · 9 comments
Assignees
Milestone

Comments

@christian-kolb
Copy link

christian-kolb commented Jul 15, 2020

I'm using an object like the following:

final class ExportMasterDataEntriesQuery implements ProjectionQueryInterface
{
    /**
     * @var UuidInterface[]
     * @psalm-var list<UuidInterface>
     */
    public array $categoryIds;

   ...

And want to deserialize this object from the following JSON:

{
  "categoryIds": [],
  "...": ""
}

The error I get is:

The type of the "categoryIds" attribute for class "App\EventSourcing\Projection\MasterDataExport\Query\ExportMasterDataEntriesQuery" must be one of "Ramsey\Uuid\UuidInterface[]" ("array" given).

My serializer is defined like the following:

$this->serializer = new Serializer(
    [
        new ArrayDenormalizer(),
        new DateTimeNormalizer(),
        new DataUriNormalizer(),
        new UuidNormalizer(),
        new UuidDenormalizer(),
        new ObjectNormalizer(
            $classMetadataFactory,
            null,
            null,
            new PhpDocExtractor()
        ),
        new PropertyNormalizer(),
    ],
    [
        new JsonEncoder(),
    ]
);

Do I have to change something in my serializer setup or is this not supported by this package? If not, would it be possible to add this functionality or could you give me a hint how to add it, then I might try my hand with a pull request.

@gbprod gbprod self-assigned this Jul 16, 2020
@gbprod gbprod added this to the V2 milestone Jul 16, 2020
@gbprod
Copy link
Owner

gbprod commented Jul 17, 2020

Hi !

Could you provide the entire stack trace please ?

@christian-kolb
Copy link
Author

Thanks for the quick reply 🙂

Yes, I will boot the project after lunch. In the meantime I've changed it to use strings and will need to change that back to produce the Stack Trace. But I will comment here within the next few hours.

@christian-kolb
Copy link
Author

christian-kolb commented Jul 17, 2020

@gbprod Here is the full stack trace as string:

#0 /var/www/project.localhost/current/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(489): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->validateAndDenormalize() 
#1 /var/www/project.localhost/current/api/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php(496): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->denormalizeParameter() 
#2 /var/www/project.localhost/current/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(237): Symfony\Component\Serializer\Normalizer\AbstractNormalizer->instantiateObject() 
#3 /var/www/project.localhost/current/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(335): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->instantiateObject() 
#4 /var/www/project.localhost/current/api/vendor/symfony/serializer/Serializer.php(191): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->denormalize() 
#5 /var/www/project.localhost/current/api/vendor/symfony/serializer/Serializer.php(142): Symfony\Component\Serializer\Serializer->denormalize() 
#6 /var/www/project.localhost/current/api/src/EventSourcing/ContractContent/CustomSerializer.php(87): Symfony\Component\Serializer\Serializer->deserialize() 
#7 /var/www/project.localhost/current/api/src/Controller/BaseController.php(153): App\EventSourcing\ContractContent\CustomSerializer->deserialize() 
#8 /var/www/project.localhost/current/api/src/Controller/MasterDataEntry/MasterDataEntryController.php(118): App\Controller\BaseController->getProjectionQueryFromRequest() 
#9 /var/www/project.localhost/current/api/vendor/symfony/http-kernel/HttpKernel.php(158): App\Controller\MasterDataEntry\MasterDataEntryController->exportJSON() 
#10 /var/www/project.localhost/current/api/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw() 
#11 /var/www/project.localhost/current/api/vendor/symfony/http-kernel/Kernel.php(201): Symfony\Component\HttpKernel\HttpKernel->handle() 
#12 /var/www/project.localhost/current/api/public/index.php(25): Symfony\Component\HttpKernel\Kernel->handle() #13 {main}

The CustomSerializer->deserialize() is just a wrapper for:

public function deserialize($data, string $type)
{
    return $this->serializer->deserialize($data, $type, JsonEncoder::FORMAT);
}

The type is the class to which the data should be deserialized.

Let me know if you need more information.

@gbprod
Copy link
Owner

gbprod commented Jul 20, 2020

Thanks, I'm working on a fix.

gbprod added a commit that referenced this issue Jul 20, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 20, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 21, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 22, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 22, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 22, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 22, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
gbprod added a commit that referenced this issue Jul 22, 2020
This commit will allow deserialization of array of UuidInterface using
PhpDocExtractor.

Ref: #12
@gbprod
Copy link
Owner

gbprod commented Jul 22, 2020

I've pushed a fix, can you try again using v1.2.1 and give me a feedback ?

Thanks

@gbprod gbprod closed this as completed Jul 22, 2020
@christian-kolb
Copy link
Author

Ah you just released 1.2.1, perfect. Yes I will try, but I will only be able to do so tomorrow. I will update you as soon as possible. Thanks for the remarkable turnaround time 🙂

@christian-kolb
Copy link
Author

@gbprod Works perfectly, thanks again for the fast response 🙂

@gbprod
Copy link
Owner

gbprod commented Jul 23, 2020

Thanks for the feedback, I'll will improve a little this lib, every feedback or feature requests are welcomes ;)

@christian-kolb
Copy link
Author

christian-kolb commented Jul 23, 2020

For now it does everything I need 🙂
But I'm a huge fan of Psalm, maybe integrating it into the library will make it more robust (not that there is a issue I'm aware of)

I will write as soon as I can think of any feature request

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

2 participants