I'm building an API using Symfony2, Doctrine and the FOSRestBundle. I would like to use the forms component to validate API requests that create or modify records and am having a few problems. I have been using the validation component on it's own but would like to move to using the forms component as it moves all validation logic out of the controller, better handles binding the request data to my entities and better aggregates error messages.
The issues I'm having are to do with fields that are not required, either when a record is being created through POST or when it's being updated through PUT. Ideally I'd like it so that a non-required field does not have to be submitted at all through HTTP but this causes the form validation to fail. For example one of the fields on an entity I'm using is a DateTime field called endTime and this is not required. If a parameter called endTime is not present in the POST or PUT request Symfony2 binds the value null from the Request to the field. When this is converted to a DateTime instance it is cast to the current date time, which is not what I want at all.
Is there any way to tell Symfony to not bind values to the entity if they don't exist in the HTTP request? This should still be safe as validation would still fail based on the annotations in the entity class. I could override the bind method but this seems like a lot of work...
Thanks for any ideas.