Symfony2 FOSRest value for null

In a web application built with Symfony2, I need to send values null

as part of a request PUT

or PATCH

FOSRestBundle endpoint. for example { "available": null }

. A database field is a type nullable

boolean

that is set by Doctrine. So the value must be 1, 0 or null

(i.e. Unknown). However, sending the value is null

ignored. This can be a problem with either Symfony2 forms or FOSRest. I tried adding to the form empty_value => null

and empty_data => null

but nothing works. Any idea if there is a parameter that allows it to be accepted null

as an option?

+3


source to share


4 answers


Boolean true or false is usually how you can tell it was canceled because it was null or unchecked because it was false, it is false anyway. So if you want the 3 options to use the select box better than the checkbox, use (Select, Yes, No) with the values ​​(null, 1, 0).



You can check it out, but I don't think it helps much https://github.com/symfony/symfony/issues/10364

+4


source


Try to install in your config:



fos_rest:
    serializer:
        serialize_null: true

      

+2


source


Maybe you can try making virtual property by sending the string "0", "1" or "null" and expose as the name of your other property.

+1


source


Set the default to NULL when designing the db and ignore the field when inserting using a query. It will automatically insert NULL.

+1


source







All Articles