I am trying to convert data from json to DTO class. I am using Symfony serializer.
But when I am trying to deserialize. It does not parse type from typed property, I guess Symfony does not support deserialization form typed property yet. Is it so? Do I have to implement my one?
DTO:
class ElkUser
{
public string $partnerUuid;
public string $contractUuid;
public DealerInfo $dealerInfo;
}
class DealerInfo
{
public string $description;
public int $dealerId;
public string $dealerName;
public bool $enabled;
public string $registrationDate;
}
Serializer config:
$normalizers = [
new DateTimeNormalizer(),
new ObjectNormalizer(
null,
null,
null,
new ReflectionExtractor
),
];
$serializer new Serializer($normalizers, [new JsonEncoder()]);
The test case when give me error:
TypeError : Typed property App\Services\CreditPilot\ElkUser::$dealerInfo must be an instance of App\Services\CreditPilot\DealerInfo, array used
$json = <<< JSON
{
"partnerUuid": "string",
"contractUuid": "string",
"dealerInfo": {
"dealerId": 0,
"dealerName": "string",
"enabled": true,
"registrationDate": "2020-03-10T12:49:08.367Z",
"contract": {
"contractNumber": "string",
"enabled": true,
"creationDate": "2020-03-10T12:49:08.367Z"
}
}
}
JSON;
$serializer->deserialize($json, ElkUser::class, 'json');