symfonysymfony-3.4jmsserializerbundlejms-serializer

JMS Serializer expressions not working in virtual property with Symfony 3.4


I recently deep dived into JMS Serializer and although I like it how the package makes a lot of things convenient for the developer in serialisation/deserialisation but there is a major lack of documentation around available options in the package.

I am trying to resolve a virtual property using expressions and I am getting following error.

The property expression_prop on MyPackageName\\SubPackage\\ClassZ requires the expression accessor strategy to be enabled.

Note: the class path has been changed to dummy path.

Here's the YAML config part for the property I am trying to create

 virtual_properties:
     expression_prop:
         exp: object.isUnCategorized()
         serialized_name: is_categorized
         groups: [tr_view]
         type: boolean

And here's the YAML config part of JMS serializer in app/config.yaml

jms_serializer:
metadata:
    auto_detection: true
    directories:
        accounting-process:
            namespace_prefix: "DummyBundleName\\SubPAth\\Application\\DTO"
            path: "%kernel.root_dir%/../src/path-to-config-directory"

Note the absolute path has again been replaced due to sensitivity of it.


Solution

  • It's necessary to install ExpressionLanguage Component

    Command for symfony 3.4:

    composer require symfony/expression-language:^3.4