Skip to content

Instantly share code, notes, and snippets.

@digitalkaoz
Last active August 29, 2015 14:07
Show Gist options
  • Save digitalkaoz/90644937a322b3739bd2 to your computer and use it in GitHub Desktop.
Save digitalkaoz/90644937a322b3739bd2 to your computer and use it in GitHub Desktop.
serializer for external classes
# app/config/config.yml
jms_serializer:
metadata:
directories:
my-file:
namespace_prefix: "My\\Ns"
path: "@MyNsBundle/Resources/config/serializer"
<?php
// My/Ns/File
namespace My\Ns;
class File
{
}
<!-- My/Ns/Bundle/Resources/config/serializer/My.Ns.File.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
<class name="My\Ns\File" exclusion-policy="ALL">
</class>
</serializer>
@stof
Copy link

stof commented Oct 9, 2014

The file name with dot-separated components of the class name should not include the namespace prefix. this is exactly what the namespace prefix is about: shortening the file name by allowing to omit the namespace prefix when all classes mapping in your folder are sharing the same namespace prefix.

@digitalkaoz
Copy link
Author

then the documentation is misleading somehow? http://jmsyst.com/libs/serializer/master/reference/xml_reference ?

@digitalkaoz
Copy link
Author

mh still not working:

jms_serializer:
    metadata:
        directories:
            issues:
                namespace_prefix: "Rs\\Issues\\"
                path: "@RsIssuesBundle/Resources/config/serializer"
 ls -la vendor/digitalkaoz/issues-bundle/Resources/config/serializer/
Github.GithubIssue.xml
Github.GithubProject.xml
<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
    <class name="Rs\Issues\Github\GithubProject" exclusion-policy="ALL">
    <!-- ... -->
    </class>

@digitalkaoz
Copy link
Author

@stof this should be correct or?

@stof
Copy link

stof commented Oct 9, 2014

Try removing the \ at the end of the namespace prefix to see whether it fixes it (I don't use a trailing backslash in my working config, I don't know whether it is important)

@digitalkaoz
Copy link
Author

tried it in all variations :/

@digitalkaoz
Copy link
Author

got it working:

jms_serializer:
    metadata:
        directories:
            issues:
                namespace_prefix: "Rs\\Issues"
                path: "@RsIssuesBundle/Resources/config/serializer/issues"
 ls -la vendor/digitalkaoz/issues-bundle/Resources/config/serializer/issues
Github.GithubIssue.xml
Github.GithubProject.xml
<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
    <class name="Rs\Issues\Github\GithubProject" exclusion-policy="ALL">
    <!-- ... -->
    </class>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment