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

Deserialization fails with groups #864

Open
reypm opened this issue Aug 27, 2021 · 2 comments
Open

Deserialization fails with groups #864

reypm opened this issue Aug 27, 2021 · 2 comments

Comments

@reypm
Copy link

reypm commented Aug 27, 2021

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps required to reproduce the problem

  1. Having a DTO class as follow:
<?php

declare(strict_types=1);

namespace App\DTO;

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Groups as SerializerGroups;
use JMS\Serializer\Annotation\Type as SerializerType;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints\NotBlank;

#[ExclusionPolicy('NONE')]
class TestDTO
{
    #[SerializerType('string')]
    #[SerializerGroups(['groupA'])]
    #[NotBlank]
    #[DateTime(format: 'Y-m-d H:i:s')]
    public string $date;

    #[SerializerType('string')]
    #[SerializerGroups(['groupA'])]
    #[NotBlank]
    public string $propA;

    #[SerializerType('string')]
    #[SerializerGroups(['groupB'])]
    #[NotBlank]
    public string $propB;
}
  1. Having the following JSON payload:
    {
      "date": "2021-07-24 13:05:00",
      "propA": "some",
      "propB": "other"
    }
  1. And trying to deserialize the above JSON into TestDTO as follow:
$deserializationContext = (DeserializationContext::create())->enableMaxDepthChecks()->setGroups(['groupA]);
$this->serializer->deserialize(json_encode($json), TestDTO::class, 'json', $deserializationContext);

Expected Result

  • A valid TestDTO object with $date and $propA filled properly

Actual Result

  • An invalid TestDTO object without $date and $propA

I am not sure if I am missing something but I have read the docs several times and apparently I am not missing anything in my code.

Installed JMS packages version:

jms/metadata                                   2.5.1              Class/method/property metadata management in PHP
jms/serializer                                 3.14.0             Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.
jms/serializer-bundle                          3.8.0              Allows you to easily serialize, and deserialize data of any complexity

@goetas
Copy link
Collaborator

goetas commented Nov 13, 2021

can yo please reproduce the issue in a separate repo or send a failing test case?

@reypm
Copy link
Author

reypm commented Nov 13, 2021

@goetas I am busy atm but I'll keep an eye on this. While I am not using groups anymore I will prepare a repo with a simple demo for this and see if the error persists in the latest versions if not then I will close this issue.

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