Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Wrong DTO's deserialization #123

Closed
endihunter opened this issue Feb 24, 2019 · 2 comments
Closed

Wrong DTO's deserialization #123

endihunter opened this issue Feb 24, 2019 · 2 comments

Comments

@endihunter
Copy link

endihunter commented Feb 24, 2019

Using symfony serializer leads to a serialization/deserialization issue:
I have complex Dto's with nested objects (also dto) which are serialized to a json (field: event_properties), but on deserialization - only top level obect is restored to a DTO:

Example:

<?php

namespace App\DTO;

use JMS\Serializer\Annotation as Serializer;

class OrderDto
{
    /**
     * @var string
     * @Serializer\Type("string")
     */
    public $orderId;

    /**
     * @var int
     * @Serializer\Type("int")
     */
    public $storeId;

    /**
     * @var string
     * @Serializer\Type("string")
     */
    public $shippingAddress;

    /**
     * @var string
     * @Serializer\Type("string")
     */
    public $comment;

    /**
     * @var OrderProductDto[]
     * @Serializer\Type("array<App\DTO\OrderProductDto>")
     */
    public $products = [];
}

class OrderProductDto
{
    /**
     * @var string
     *
     * @Serializer\Type("string")
     */
    public $sku;

    /**
     * @var int
     *
     * @Serializer\Type("int")
     */
    public $quantity;
}

on deserialisation, the $products is just a multidimensional array, instead of OrderProductDto[]

hope it's clear enough...

Great job on this package!

@freekmurze
Copy link
Member

If you have problems with serializing and deserializing events I suggest you create a custom serializer that can handle your events.

@gdebrauwer
Copy link

@endihunter Have you found a way to create a custom serializer to handle object serialisation/deserialization?

@freekmurze Do you maybe have an example of a custom serializer?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants