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

Handling stdClass and other datasource objects #67

Open
mabar opened this issue Jun 20, 2023 · 4 comments
Open

Handling stdClass and other datasource objects #67

mabar opened this issue Jun 20, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@mabar
Copy link
Member

mabar commented Jun 20, 2023

Description

Currently if processor is given an output from json_decode($value), an stdClass is casted to array in case it's in place of a MappedObjectValue. But stdClass makes sense to handle also in case of an ArrayOf and a ListOf.

Handling should be also available in Value in case printer decides to print an invalid value.

We should also consider that fix on user side is as simple as json_decode($value, true) and that it may work only for some formats:

  • neon may use an entity which extends stdClass and adds an extra properties.
  • xml may be returned as e.g. a SimpleXMLElement and we have no way of casting it to an array, handling attributes or printing errors while maintaining the original xml structure

Addition information

No response

Related issues

No response

@mabar mabar added the enhancement New feature or request label Jun 20, 2023
@mabar
Copy link
Member Author

mabar commented Jun 20, 2023

jms/serializer has Xml* attributes for that - see https://jmsyst.com/libs/serializer/master/reference/annotations

use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
use JMS\Serializer\Annotation\XmlRoot;

/** @XmlRoot("price") */
class Price
{
    /** @XmlAttribute */
    private $currency = 'EUR';

    /** @XmlValue */
    private $amount = 1.23;
}

XmlValue should probably be default

@mabar
Copy link
Member Author

mabar commented Jun 20, 2023

symfony/serializer does something similar too, but the exact format should be mainly declared by the object and not in global config
https://symfony.com/doc/current/components/serializer.html#the-xmlencoder

@mabar
Copy link
Member Author

mabar commented Jun 21, 2023

For now I removed support for stdClass from processor. Proper support for various formats will be implemented later 5edbc1a

@mrceperka
Copy link
Contributor

TIL that any stdClass in $data will cause validation to fail. But it will not tell you where it failed.

Most like this to blame:

private function ensureDataProcessable($data, MappedObjectContext $context): array

I might add a test case for this and we might also want to add error to type when this happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants