Are you using the second parameter of addMetadataDir
?
From JMS\Serializer\SerializerBuilder.php
:
/**
* Adds a directory where the serializer will look for class metadata.
*
* The namespace prefix will make the names of the actual metadata files a bit shorter. For example, let's assume
* that you have a directory where you only store metadata files for the ``MyApplication\Entity`` namespace.
*
* If you use an empty prefix, your metadata files would need to look like:
*
* ``my-dir/MyApplication.Entity.SomeObject.yml``
* ``my-dir/MyApplication.Entity.OtherObject.xml``
*
* If you use ``MyApplication\Entity`` as prefix, your metadata files would need to look like:
*
* ``my-dir/SomeObject.yml``
* ``my-dir/OtherObject.yml``
*
* Please keep in mind that you currently may only have one directory per namespace prefix.
*
* @param string $dir The directory where metadata files are located.
* @param string $namespacePrefix An optional prefix if you only store metadata for specific namespaces in this directory.
*
* @return SerializerBuilder
*
* @throws InvalidArgumentException When a directory does not exist
* @throws InvalidArgumentException When a directory has already been registered
*/
public function addMetadataDir($dir, $namespacePrefix = '')
{
// ...
}
It appears that if you specify the second parameter, you can achieve what you're looking for.