Monthly Archives: March 2016

You are browsing the site archives by month.

Could not denormalize object of type , no supporting normalizer found.

I tried to create a custom Rest API with Drupal 8 and it was working great with GET operations. Problem is I wanted more, what about POST, PATCH, PUT, DELETE, … operations ?

Only GET examples were found about Drupal Rest API and nobody had any explanation about this POST response error:

Could not denormalize object of type , no supporting normalizer found.

So I had a look in Drupal Core and found out you need this interesting serialization_class comment annotation. Example with EntityResource:

Actually, if you implement GET, you don’t need this serialization_class to be filled because you only deal with primitive types, but if you want to implement something else like POST, PUT, …, this should be filled with an EntityType so Drupal would be able to understand and cast your parameters to the destination Entity.

Example, you create a VoteEntity and you need to implement GET and POST Rest apis, this should do the trick:

 

Hope this helps.