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 update #34

Open
patgod85 opened this issue Feb 18, 2016 · 3 comments
Open

Datetime update #34

patgod85 opened this issue Feb 18, 2016 · 3 comments

Comments

@patgod85
Copy link

Hi. I have an entity with DateTime field

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="work_start", type="datetime", nullable=true)
     * @Serializer\Expose
     * @Serializer\Type("DateTime")
     */
    private $workStart;

Every other field updates correctly with PUT request. But the field.

I receive data from client in format 2012-02-25T21:00:00.000Z

Can you assist me to find a clue?

Thanks

@davidwdan
Copy link
Member

That's an iso date, so try: * @Serializer\Type("DateTime<'c'>")

@patgod85
Copy link
Author

Yes, I've tried it. It doesn't help

As I see with morning fresh mind, the problem relates to a name of the field but a type.

  1. When an Entity is serialized by GET action a client receives model with property work_start.
  2. Client edits the model and sends it to server in format {"name": "Juan", surname: "Lopez", "work_start": "2012-02-25T21:00:00.000Z"}
  3. In PUT action there is the line
        $this->removeExtraFields($request, $form);

it calls a code from
https://github.com/voryx/restgeneratorbundle/blob/master/src/Voryx/RESTGeneratorBundle/Controller/VoryxController.php
I do print arrays to see what to be removed

    /**
     * Get rid on any fields that don't appear in the form
     *
     * @param Request $request
     * @param Form $form
     */
    protected function removeExtraFields(Request $request, Form $form)
    {
        $data     = $request->request->all();
        $children = $form->all();
print_r([$data, array_keys($children)]);
        $data     = array_intersect_key($data, $children);
        $request->request->replace($data);
    }

And have that:

Array
(
    [0] => Array
        (
            [name] => Juan
            [surname] => Lopez
            [work_start] => 2012-10-10T21:00:00.000Z
        )

    [1] => Array
        (
            [0] => name
            [1] => surname
            [2] => workStart
        )

)

So the new value of workStart property removed because of different naming strategy.

Is there a right way to avoid the problem? I assume it should work with JMS\Serializer\Naming\IdenticalPropertyNamingStrategy, but I prefer default naming strategy.

@patgod85
Copy link
Author

Sorry,
Is there any advice for me?

patgod85 added a commit to patgod85/timesheet2 that referenced this issue Feb 25, 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