Extending serializer metadata

Hi all. For a feature in a Sylius plugin I’ve created, I’m using ResourceAutocompleteChoiceType to let the admin user select a product. Works great, but now I need the sylius_admin_ajax_product_by_name_phrase AJAX request to include some additional fields in the response and I’m struggling to find a clean way to do this.

I see that the response content is configured in
ProductBundle/Resources/config/serializer/Model.Product.yml
but of course I can’t edit that file, I need to extend it from my plugin somehow.

JMS Serializer finds that definition file through this config:

jms_serializer:
    metadata:
        directories:
            sylius_product:
                namespace_prefix: Sylius\Component\Product
                path: '@SyliusProductBundle/Resources/config/serializer'

I could override that to point to my plugin instead, but then I’d have to duplicate all the product definitions which seems way too heavy-handed for adding one or two fields for this very specific purpose. (And you can’t define two directories for the same namespace_prefix – I tried.)

Anybody know a better way to extend the serializer metadata? Or a better way to accomplish what I need?

have you tried Serializer handlers? https://jmsyst.com/libs/serializer/master/handlers

I haven’t, and that looks promising. Thank you!