Thomas Spycher Thomas Spycher - 1 year ago 156
reST (reStructuredText) Question

Symfony Restful Post: JMSSerializerBundle vs Symfony Form Components

As far as i understand it right JMSSerializerBundle's deserialisation does the same same as the symfony form component when a controller gets an post/put/patch request?

So either i create a symfony custom formType for e.g. an UserType and when i get a request i do something like $form->handleRequest($request) or i use JMSSerializerBundle to unserialize the request to a document/entity which gets finally stored.

Does anyone have experience with both methods? Currently i'm only familiar with the form way... Which one should i choose?

The Application i'm talking about is purely Restful, there are no twig html templates and FOSRestbundle is doing all the RESTful routing.

Answer Source

In our restfull API we usually use JMSSerializerBundle to handle the deserialization of entities, then the Symfony Validator component to ensure that the entities fulfill all the required conditions before pushing/updating them in database. Works pretty well, lighter than the form component.

Anyway The Form component would not be able to deserialize the json/xml so you'll have to use JMSSerializerBundle.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download