{"action":"created","issue":{"url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/2","repository_url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider","labels_url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/2/comments","events_url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/2/events","html_url":"https://github.com/jdesrosiers/silex-jms-serializer-provider/issues/2","id":163807746,"number":2,"title":"Setting of serializer.deserializationVisitors","user":{"login":"niabot","id":2789252,"avatar_url":"https://avatars.githubusercontent.com/u/2789252?v=3","gravatar_id":"","url":"https://api.github.com/users/niabot","html_url":"https://github.com/niabot","followers_url":"https://api.github.com/users/niabot/followers","following_url":"https://api.github.com/users/niabot/following{/other_user}","gists_url":"https://api.github.com/users/niabot/gists{/gist_id}","starred_url":"https://api.github.com/users/niabot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niabot/subscriptions","organizations_url":"https://api.github.com/users/niabot/orgs","repos_url":"https://api.github.com/users/niabot/repos","events_url":"https://api.github.com/users/niabot/events{/privacy}","received_events_url":"https://api.github.com/users/niabot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-05T09:27:26Z","updated_at":"2016-07-20T02:29:39Z","closed_at":null,"body":"I wonder how i can add a custom Visitor that extends the `JsonDeserializationVisitor`. The constructor of `JsonDeserializationVisitor` requires an instance of `PropertyNamingStrategyInterface`, but i can't access it within the configuration because 'serializer.namingStrategy' is not added to Pimple if it is not defined as an configuration option.\r\n\r\n``` php\r\n$app->register(new JmsSerializerServiceProvider(), [\r\n  // 'serializer.namingStrategy' => new CamelCaseNamingStrategy(),\r\n  'serializer.deserializationVisitors' => [\r\n    'json' => new StrictJsonDeserializationVisitor($app['serializer.namingStrategy']), // fails, key is missing\r\n  ]\r\n]);\r\n```\r\n\r\nThe example above works if i set the naming strategy and overwrite the default one, but it fails if i don't set it, because 'serializer.namingStrategy' will never be set.\r\n"},"comment":{"url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/comments/233822231","html_url":"https://github.com/jdesrosiers/silex-jms-serializer-provider/issues/2#issuecomment-233822231","issue_url":"https://api.github.com/repos/jdesrosiers/silex-jms-serializer-provider/issues/2","id":233822231,"user":{"login":"jdesrosiers","id":716571,"avatar_url":"https://avatars.githubusercontent.com/u/716571?v=3","gravatar_id":"","url":"https://api.github.com/users/jdesrosiers","html_url":"https://github.com/jdesrosiers","followers_url":"https://api.github.com/users/jdesrosiers/followers","following_url":"https://api.github.com/users/jdesrosiers/following{/other_user}","gists_url":"https://api.github.com/users/jdesrosiers/gists{/gist_id}","starred_url":"https://api.github.com/users/jdesrosiers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdesrosiers/subscriptions","organizations_url":"https://api.github.com/users/jdesrosiers/orgs","repos_url":"https://api.github.com/users/jdesrosiers/repos","events_url":"https://api.github.com/users/jdesrosiers/events{/privacy}","received_events_url":"https://api.github.com/users/jdesrosiers/received_events","type":"User","site_admin":false},"created_at":"2016-07-20T02:29:39Z","updated_at":"2016-07-20T02:29:39Z","body":"Actually, you don't need to override the `serializer.builder` service.  You can use the built in functionality when it is available and use the `serializer.builder` service to do the fancy stuff.  You can even override the `serializer` service to make it a little cleaner.\r\n\r\n```php\r\n$app->register(new JmsSerializerServiceProvider(), [\r\n    'serializer.annotationReader' => $app['meta.annotation.reader'],\r\n    'serializer.namingStrategy' => new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy())\r\n]);\r\n\r\n$app['serializer'] = $app->shared(function (Application $app) {\r\n    $app['serializer.builder']->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($app['serializer.namingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('json', new StrictJsonSerializationVisitor($app['serializer.namingStrategy']));\r\n    $app['serializer.builder']->setDeserializationVisitor('xml', new StrictXmlDeserializationVisitor($app['serializer.namingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('xml', new StrictXmlSerializationVisitor($app['serializer.namingStrategy']));\r\n    $app['serializer.builder']->setDeserializationVisitor('yml', new StrictYamlDeserializationVisitor($app['serializer.namingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('yml', new StrictYamlSerializationVisitor($app['serializer.namingStrategy']));\r\n\r\n    return $app[\"serializer.builder\"]->build();\r\n});\r\n```\r\n\r\nAfter some more thought, I don't think there is a good way to build this into a silex provider.  I think the above is the best way to do it except for the part where you need to define `serializer.namingStrategy` even though it is the default.  So, I'm adding a new service `serializer.propertyNamingStrategy` to access the naming strategy that is being used by the builder.  So, the example could now be written like the following.\r\n\r\n```php\r\n$app->register(new JmsSerializerServiceProvider(), [\r\n    'serializer.annotationReader' => $app['meta.annotation.reader']\r\n]);\r\n\r\n$app['serializer'] = $app->shared(function (Application $app) {\r\n    $app['serializer.builder']->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($app['serializer.propertyNamingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('json', new StrictJsonSerializationVisitor($app['serializer.propertyNamingStrategy']));\r\n    $app['serializer.builder']->setDeserializationVisitor('xml', new StrictXmlDeserializationVisitor($app['serializer.propertyNamingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('xml', new StrictXmlSerializationVisitor($app['serializer.propertyNamingStrategy']));\r\n    $app['serializer.builder']->setDeserializationVisitor('yml', new StrictYamlDeserializationVisitor($app['serializer.propertyNamingStrategy']));\r\n    $app['serializer.builder']->setSerializationVisitor('yml', new StrictYamlSerializationVisitor($app['serializer.propertyNamingStrategy']));\r\n\r\n    return $app[\"serializer.builder\"]->build();\r\n});\r\n```\r\n"}}
{"actor":{"display_login":"jdesrosiers"}}