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

Jms deserializer class with parent properties #774

Closed
shubaivan opened this issue Oct 30, 2019 · 1 comment
Closed

Jms deserializer class with parent properties #774

shubaivan opened this issue Oct 30, 2019 · 1 comment

Comments

@shubaivan
Copy link

shubaivan commented Oct 30, 2019

I use "jms/serializer": "^3.3", stand alone. And my goal create parent class for two child with common properties. I did it. Cretae parent class Request and two child - ApiRequest and FormRequest. Child differ in that they have different serializer names for properties that's all. I use yml mapping.

/**
 * Class Request
 */

class Request
{
/**
 * @var SignatureType
 * @Assert\NotBlank()
 */
public $signatureType;

Child

/**
 * Class ApiRequest
 * @package CDB\Collection\DTO
 * @RequestApplication()
 * @SignatoryTypeConstraint()
 */
class ApiRequest extends Request
{

}

and child config CDB.Collection.DTO.ApiRequest.yml

CDB\Collection\DTO\ApiRequest:
  exclusion_policy: ALL
  properties:
    signatureType:
      expose: true
      type: string
      serialized_name: signatureType

For parent I don't have config

and when I try deserialize json

{
 
    "signatureType": "bankid"
}

Object have empty property

When I try deserializer json

{
 
    "signature_type": "bankid"
}

I determined that metadata for child class did not contain `propertyMetadata. When I remove condtiion in

jms/serializer/src/Metadata/Driver/YamlDriver.php

from

            foreach ($class->getProperties() as $property) {
                if ($property->class !== $name || (isset($property->info) && $property->info['class'] !== $name)) {
                    continue;
                }

to

            foreach ($class->getProperties() as $property) {
                if ((isset($property->info) && $property->info['class'] !== $name) {
                    continue;
                }

$metadata for my class metadata began to contain data about my child class. Because $class->getProperties() reflection function which get properties from parent, that's why property class name and class for which metadata generated is different.
Maybe I select wrong way or who know how to correct work with yml configuration for class whose properties from parent classes ?

@goetas
Copy link
Collaborator

goetas commented Oct 30, 2019

I guess this is a duplicate of schmittjoh/serializer#1135

@goetas goetas closed this as completed Oct 30, 2019
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