0

A lot of my Web API interfaces use DateTime return types or parameters as follows.

interface TestInterface
{
    /**
     * @param \DateTime $value
     * @return void
     */
    public function setDate(\DateTime $value);

    /**
     * Gets the current date.
     * 
     * @return \DateTime
     */
    public function getDate() : \DateTime;
}

When trying to request Web API end-point which has TestInterface[] as return type. I get the following error in Magento 2.

Each getter must have a doc block. See DateTime::format()

So I assume there is no DateTime-Formatter in Magento 2. I took a look into DataObjectProcessor.php and the ServiceOutputProcessor.php assuming it would be an option to provide a custom formatter when an Object is of type \DateTime.

Any suggestions or solution to this problem? Best would be if my DateTime ojects would end up being ISO8601 serialized as in JSON standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.