FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

Request Body Converter with Param Converter

Open FlorinAsavoaie opened this issue 7 years ago • 3 comments

I would expect to have the following feature:

/**
 * @View()
 * @ParamConverter(null, converter="fos_rest.request_body", options={"object_to_populate" = "post"})
 */
public function putAction(Post post) {
    return $post;
}

When doing an HTTP PUT to /posts/{id} where {id} is a valid ID of a post, the body converter would automatically use the object_to_populate option of the Serializer component to update the post parameter in place, after retrieving the post from the ParamConverter.

I did not get the time to look into how difficult this would be to implement but any suggestions would be welcome.

FlorinAsavoaie avatar Jun 05 '17 12:06 FlorinAsavoaie

having the same nightmare since days as well

MedUnes avatar Aug 07 '18 19:08 MedUnes

any solution for this ?

oussama-aitmi avatar Apr 28 '20 16:04 oussama-aitmi

I came around the problem by creating my own decorator converter for RequestBodyParamConverter. This converter looks for an already converted attribute (e.g. the doctrine object you want to patch), sets the object_to_populate option in RequestBodyParamConverter's deserializationContext before letting RequestBodyParamConverter do the work.

I can provide a pull request to integrate it into FOSRestBundle if desired.

Ovascos avatar Jan 06 '21 20:01 Ovascos