Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make possible to set ArrayCollectionHandler classes from outside #1131

Closed
alexander-schranz opened this issue Oct 9, 2019 · 4 comments
Closed

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Oct 9, 2019

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes/no?

The ArrayCollectionHandler classes are currently hardcoded. It would be good if the ArrayCollectionHandler get its classes from outside and so in the jms serializer bundle I could use PrependExtension in my bundle config to add a class to the ArrayCollectionHandler.

Expected Result

  • Allow to add ArrayCollection classes to Handler

Actual Result

  • Classes are hardcoded and no other classes can be added from outside.
@goetas
Copy link
Collaborator

goetas commented Oct 9, 2019

What do you mean by "hardcoded" ?

If you want to add extra extensions you can do this:

$serializerBuilder = SerializerBuilder::create();
$serializerBuilder->addMetadataDir('metadata dir', 'TestNs');
$serializerBuilder->configureHandlers(function (HandlerRegistryInterface $handler) use ($serializerBuilder) {
     // default handlers
    $serializerBuilder->addDefaultHandlers();
   // your handlers
   $handler->registerSubscribingHandler(new YourhandlerHere());
});

@alexander-schranz
Copy link
Contributor Author

@goetas sorry I mean this classes are hardcoded:

$collectionTypes = [
'ArrayCollection',
'Doctrine\Common\Collections\ArrayCollection',
'Doctrine\ORM\PersistentCollection',
'Doctrine\ODM\MongoDB\PersistentCollection',
'Doctrine\ODM\PHPCR\PersistentCollection',
];

And would think about something like this in the JMS SerializerBundle to add your custom ArrayCollectionClasses:

jms_serializer:
     handlers:
          array_collection:
                classes:
                      - CustomClass

@goetas
Copy link
Collaborator

goetas commented Oct 9, 2019

you can easily register more handlers

<service id="app.my_handler" class="JMS\Serializer\Handler\ArrayCollectionHandler">
    <tag name="jms_serializer.handler" type="CustomClass" 
                direction="serialization" format="json"
                method="serializeCollection" />

    <tag name="jms_serializer.handler" type="CustomClass"
                direction="deserialization" format="json"
                method="deserializeCollection" />
</service>

This will register ArrayCollectionHandler for the CustomClass type

@alexander-schranz
Copy link
Contributor Author

Oh didn't thought about that solution. Great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants