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

Version 5.3.0 does not work with annotations anymore #931

Closed
sylviavdv opened this issue Jun 12, 2023 · 2 comments
Closed

Version 5.3.0 does not work with annotations anymore #931

sylviavdv opened this issue Jun 12, 2023 · 2 comments

Comments

@sylviavdv
Copy link

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

Steps required to reproduce the problem

  1. update from 5.2.1 to 5.3.0
  2. have objects that use jms annotations

Expected Result

  • the objects are correctly serialized or unserialized

Actual Result

  • the serialized object is empty

In DependencyInjection/JMSSerializerExtension.php, a new driver is added, the attribute_driver, which has priority over the annotation driver.

                $metadataDrivers = [
                    new Reference('jms_serializer.metadata.yaml_driver'),
                    new Reference('jms_serializer.metadata.xml_driver'),
                    new Reference('jms_serializer.metadata.attribute_driver'),
                    new Reference('jms_serializer.metadata.annotation_driver'),
                ]; 

Now in vendor/jms/metadata/src/Driver/DriverChain.php, the annotation driver always produces a metadata object, even though no jms annotations are used. The result object has no metadata, but it's not null.

JMS\Serializer\Metadata\ClassMetadata {#7855
  +name: "stdClass"
  +methodMetadata: []
  +propertyMetadata: []
  +fileResources: []
  +createdAt: 1686566431
  +preSerializeMethods: []
  +postSerializeMethods: []
  +postDeserializeMethods: []
  +xmlRootName: null
  +xmlRootNamespace: null
  +xmlRootPrefix: null
  +xmlNamespaces: []
  +accessorOrder: null
  +customOrder: null
  +usingExpression: false
  +isList: false
  +isMap: false
  +discriminatorDisabled: false
  +discriminatorBaseClass: null
  +discriminatorFieldName: null
  +discriminatorValue: null
  +discriminatorMap: []
  +discriminatorGroups: []
  +xmlDiscriminatorAttribute: false
  +xmlDiscriminatorCData: true
  +xmlDiscriminatorNamespace: null
  +excludeIf: null
}

Therefore we never reach the AnnotationDriver and all jms annotations are subsequently ignored.

@mbabker
Copy link
Contributor

mbabker commented Jun 12, 2023

I don't have a clean way of testing this since the main app I work in has the jms_serializer.metadata_driver service overloaded to fully remove annotation support (we have them completely disabled), but looking over #920, the one thing I can think to suggest is to flip the order of the drivers here.

But, I get the feeling this is exposing a bigger problem with those drivers if the annotation or attribute drivers are returning unconfigured Metadata\ClassMetadata objects instead of null like the XML or YAML drivers do when there is no metadata, and it's only showing up because of the changes introduced with that PR.

@mbabker
Copy link
Contributor

mbabker commented Jun 12, 2023

schmittjoh/serializer#1494 looks to clean up the underlying root cause, if you're able to test that.

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

3 participants