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

DateTime doesn't parse correctly from json #54

Closed
FoxxMD opened this issue May 3, 2016 · 1 comment
Closed

DateTime doesn't parse correctly from json #54

FoxxMD opened this issue May 3, 2016 · 1 comment

Comments

@FoxxMD
Copy link

FoxxMD commented May 3, 2016

I've got a class with a DateTime property

/**
 * @var DateTime
 */
public $activeAt;

When mapping to the class from a json object which has a serialized DateTime object

stdClass Object
(
    [date] => 2015-05-01 00:00:00.000000
    [timezone_type] => 3
    [timezone] => UTC
)

An exception is thrown

DateTime::setDate() expects exactly 3 parameters, 1 given

In setProperty() in JsonMapper.php (line 381)


I see under Supported Type names that DateTime is not listed, but immediately after that in simple type mapping there is an example given using DateTime.

Do I need to enforce the DateTime on the serializing object be output as date in order for jsonmapper to correctly parse it?

@cweiske
Copy link
Owner

cweiske commented May 4, 2016

The DateTime example shows how a single string in JSON is converted to a DateTime object.

You are trying to map a whole JSON object with three properties onto a DateTime object. So JsonMapper creates a DateTime object, and then tries to set each of the properties separately.
This will not work.

You should add a setActiveAt method that handles the conversion of the JSON object onto DateTime itself.

@cweiske cweiske closed this as completed May 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants