Код: Выделить всё
test
1
2
< /code>
У меня есть класс, который я хотел бы покинуть это. Похоже: < /p>
class MyObject
{
private Return $return;
/** @var array */
private array $component = [];
// getters and setters here
}
< /code>
класс «return» имеет «тип» -property, класс «компонент» имеет «ID», как с Getters, так и с сетевами. < /p>
Это мой (текущий) сериализатор: < /p>
$serializer = new Serializer(
[
new ArrayDenormalizer(),
new ObjectNormalizer(propertyTypeExtractor: new ReflectionExtractor()),
],
[new XmlEncoder()]
);
< /code>
Deserialization My XML теперь даст следующий результат: < /p>
^ App\ValueObject\MyObject^ {
-return: App\ValueObject\Return^ {
-type: "test"
}
-component: array:1 [
"item" => array:2 [
0 => array:1 [
"ID" => "1"
],
1 => array:1 [
"ID" => "2"
(...)
< /code>
В то время как ожидаемый вывод такого: < /p>
^ App\ValueObject\MyObject^ {
-return: App\ValueObject\Return^ {
-type: "test"
}
-component: array:2 [
0 => App\ValueObject\Component^ {
-id: "1"
},
1 => App\ValueObject\Component^ {
-id: "2"
}
(...)
< /code>
Таким образом, Deserialization return-object работает, как и ожидалось, отображение XML с моим массивом компонентов-объектов не имеет.-component: array:1 [ "item" => array:1 [ 0 => array:1 [ "ID" => "1" ] ]Код: Выделить всё
-component: array:1 [ "item" => array:1 [ "ID" => "1" ] ]Код: Выделить всё
$phpDocExtractor = new PhpDocExtractor();
$typeExtractor = new PropertyInfoExtractor(
typeExtractors: [new ConstructorExtractor([$phpDocExtractor]), $phpDocExtractor, new ReflectionExtractor()]
);
< /code>
, который будет создавать это: < /p>
-component: array:1 [
0 => App\ValueObject\Component^ {
-id: ""
< /code>
Таким образом, есть только один компонент-объект (вместо массива 2), также он пуст (идентификатор отсутствует). То же самое происходит, если я просто использую phpdocexptractor Я также играл с @var-comment для Component , используемый
Код: Выделить всё
arrayNext stop: Based on this post I converted my $component to ArrayCollection and added addComponent and removeComponent to the Component-class, but nothing changes, the addComponent-function is only called once with an array of arrays which are not deserialized to my Компонентный класс. ?>
Подробнее здесь: https://stackoverflow.com/questions/773 ... of-objects
Мобильная версия